Skip to content

Commit

Permalink
add read stream
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjscc committed Nov 14, 2024
1 parent 5acc667 commit 4f80c02
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Bandwidth.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public function file(string $path, $p = 0, $length = -1)
return $stream;
}

public function stream($stream)
{
$stream = new \React\Stream\ThroughStream();
$stream->on('data', function ($data) use ($stream) {
$this->concurrent->concurrent(function() use ($stream, $data){
return $this->bucket->removeTokens(1024 * strlen($data))->then(function () use ($stream, $data) {
$stream->write($data);
});
});
});
return $stream;
}

protected function fileStream($file, $stream, $p, $size)
{

Expand Down

0 comments on commit 4f80c02

Please sign in to comment.