Skip to content

Commit

Permalink
fix bug that bytesLeft() returned void when created with filename but…
Browse files Browse the repository at this point in the history
… no compression prefix
  • Loading branch information
Frank Kleine committed Jul 20, 2016
1 parent 50a8848 commit 3080ffc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

### Other changes

* fixed `stubbles\streams\InputStreamIterator` swalling the last line
* fixed `stubbles\streams\InputStreamIterator` swalling the last line
* fixed `stubbles\streams\file\FileInputStream::bytesLeft()` returning void when created with filename but not prefixed with _compress.*://_


7.0.0 (2016-01-11)
Expand Down
2 changes: 2 additions & 0 deletions src/main/php/file/FileInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected function getResourceLength(): int
} elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') {
return filesize(substr($this->fileName, 17));
}

return parent::getResourceLength();
}

/**
Expand Down
40 changes: 40 additions & 0 deletions src/test/php/file/FileInputStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ public function castFromAnythingElseThrowsInvalidArgumentException()
->throws(\InvalidArgumentException::class);
}

/**
* @test
* @since 8.0.0
*/
public function reportsBytesLeft()
{
$fileInputStream = new FileInputStream(vfsStream::url('home/test.txt'));
assert($fileInputStream->bytesLeft(), equals(3));
}

/**
* @test
* @since 8.0.0
*/
public function reportsBytesLeftWhenConstructedWithResource()
{
$fileInputStream = new FileInputStream(fopen(vfsStream::url('home/test.txt'), 'rb'));
assert($fileInputStream->bytesLeft(), equals(3));
}

/**
* @test
* @since 8.0.0
*/
public function reportsBytesLeftForGzCompressedFilesBasedOnFilesize()
{
$fileInputStream = new FileInputStream('compress.zlib://' . __DIR__ . '/../../resources/file.gz');
assert($fileInputStream->bytesLeft(), equals(37));
}

/**
* @test
* @since 8.0.0
*/
public function reportsBytesLeftForBzCompressedFilesBasedOnFilesize()
{
$fileInputStream = new FileInputStream('compress.bzip2://' . __DIR__ . '/../../resources/file.bz2');
assert($fileInputStream->bytesLeft(), equals(46));
}

/**
* @test
*/
Expand Down
Binary file added src/test/resources/file.bz2
Binary file not shown.
Binary file added src/test/resources/file.gz
Binary file not shown.

0 comments on commit 3080ffc

Please sign in to comment.