Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

[IO] add stream/handle copy function #44

Open
azjezz opened this issue Apr 12, 2019 · 1 comment
Open

[IO] add stream/handle copy function #44

azjezz opened this issue Apr 12, 2019 · 1 comment

Comments

@azjezz
Copy link
Contributor

azjezz commented Apr 12, 2019

while using HH\Lib\Experimental\IO i came across multiple situations where i needed to copy a read handle content to a write handle content.

example :

  • moving uploaded file content ( from temporary file )
  • writing response body to IO\request_output ( php://memory -> php://output )

the propose of this issue is to propose adding a copy function to copy a read handle content to a write handle.

copy pseudo implementation :

function copy(
  IO\ReadHandle $from, IO\WriteHandle $to, int $maxLength = 8192
): Awaitable<int> {
  while from.isNotEof
    content = from.read max_length
    to.write content
}

copy_range pseudo implementation :

function copy_range(
  IO\ReadHandle $from, IO\WriteHandle $to, int $length, int $maxLength = 8192
): Awaitable<void> {
  while length >= max_length and from.isNotEof
    content = from.read max_length
    length -= content.length
    to.write content
  
  if length > 0 and from.isNotEof
    content = from.read length
    to.write content
}
@fredemmott fredemmott changed the title [IO] add copy function [IO] add stream/handle copy function Oct 28, 2019
@fredemmott
Copy link
Contributor

edited title to make it clear that this is distinct to a Filesystem\copy or OS\copy, covered by #29

azjezz added a commit to azjezz/hsl-experimental that referenced this issue Apr 2, 2020
azjezz added a commit to azjezz/hsl-experimental that referenced this issue Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants