Skip to content

Commit

Permalink
support start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjscc committed Oct 1, 2024
1 parent 7d6df61 commit 5acc667
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Bandwidth.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(int $bucketSize = 0, int $tokensPerInterval = 1024,
}
}

public function file(string $path)
public function file(string $path, $p = 0, $length = -1)
{
$stream = new \React\Stream\ThroughStream();

Expand All @@ -39,15 +39,23 @@ public function file(string $path)
} else {
throw new \RuntimeException($path. ' is not a file');
}
})->then(function ($stat) use ($stream) {
})->then(function ($stat) use ($stream, $p, $length) {
if ($this->queue) {
return $this->concurrent->concurrent(function () use ($stream, $stat) {
return $this->concurrent->concurrent(function () use ($stream, $stat, $p, $length) {
$file = $this->filesystem->file($stat->path());
return $this->fileStream($file, $stream, 0, $stat->size());
$size = $stat->size();
if ($length > 0) {
$size = min($size, $p + $length);
}
return $this->fileStream($file, $stream, $p, $size);
});
} else {
$file = $this->filesystem->file($stat->path());
return $this->fileStream($file, $stream, 0, $stat->size());
$size = $stat->size();
if ($length > 0) {
$size = min($size, $p + $length);
}
return $this->fileStream($file, $stream, $p, $size);
}
}, function ($e) use ($stream) {
$stream->emit('error', [$e]);
Expand Down

0 comments on commit 5acc667

Please sign in to comment.