Skip to content

Commit

Permalink
add Stream::size()
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Oct 15, 2023
1 parent 8cf0a35 commit 902b482
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.2.0 - 2023-10-15

### Added

- `Innmind\IO\Readable\Stream::size()`

## 2.1.0 - 2023-10-15

### Added
Expand Down
9 changes: 9 additions & 0 deletions src/Readable/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Innmind\TimeContinuum\ElapsedPeriod;
use Innmind\Stream\{
Readable as LowLevelStream,
Stream\Size,
Watch,
};
use Innmind\Immutable\{
Expand Down Expand Up @@ -140,4 +141,12 @@ public function lines(): Lines
$this->encoding,
);
}

/**
* @return Maybe<Size>
*/
public function size(): Maybe
{
return $this->stream->size();
}
}
23 changes: 23 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,27 @@ public function testReadRealFileByLines()
$this->assertSame("SOFTWARE.\n", $lines[20]->toString());
$this->assertSame('', $lines[21]->toString());
}

public function testSize()
{
$this
->forAll(Set\Strings::any())
->then(function($content) {
$stream = Stream::ofContent($content);
$size = IO::of(Select::waitForever(...))
->readable()
->wrap($stream)
->size()
->match(
static fn($size) => $size->toInt(),
static fn() => null,
);

$this->assertNotNull($size);
$this->assertSame($size, $stream->size()->match(
static fn($size) => $size->toInt(),
static fn() => null,
));
});
}
}

0 comments on commit 902b482

Please sign in to comment.