-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GH-9673: $length argument for fpassthru
This implements an optional $length argument to fpassthru, SplFileObject::fpassthru and gzpassthru for partially copying the file to the output. The behaviour of this new argument has the same behaviour as the $length argument of stream_copy_to_stream. Internally, a new macro and function is introduced: _php_stream_passthru_with_length. _php_stream_passthru now calls the new function to perform its tasks without introducing a BC break internally. This unfortunately has one BC break: classes overriding SplFileObject must update the method signature of fpassthru to add the new argument.
- Loading branch information
Showing
16 changed files
with
220 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
ext/spl/tests/SplFileObject/SplFileObject_fpassthru_with_length.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
SplFileObject::fpassthru function - functionality test with length | ||
--FILE-- | ||
<?php | ||
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.csv'); | ||
$read = []; | ||
$read[] = $obj->fpassthru(1); | ||
echo "\n"; | ||
$read[] = $obj->fpassthru(10); | ||
echo "\n"; | ||
$read[] = $obj->fpassthru(0); | ||
echo "\n"; | ||
$read[] = $obj->fpassthru(-10000); | ||
echo "\n"; | ||
print_r($read); | ||
?> | ||
--EXPECT-- | ||
f | ||
irst,secon | ||
|
||
d,third | ||
1,2,3 | ||
4,5,6 | ||
7,8,9 | ||
0,0,0 | ||
|
||
Array | ||
( | ||
[0] => 1 | ||
[1] => 10 | ||
[2] => 0 | ||
[3] => 32 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--TEST-- | ||
Test fpassthru() function with length | ||
--FILE-- | ||
<?php | ||
$file_name = __DIR__."/passthru_with_length.tmp"; | ||
$file_write = fopen($file_name, "w"); | ||
fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz"); | ||
fclose($file_write); | ||
|
||
$file_read = fopen($file_name, "r"); | ||
|
||
echo "Test consecutive reads\n"; | ||
$read = []; | ||
$read[] = fpassthru($file_read, 1); | ||
echo "\n"; | ||
$read[] = fpassthru($file_read, 3); | ||
echo "\n"; | ||
$read[] = fpassthru($file_read, 0); | ||
echo "\n"; | ||
$read[] = fpassthru($file_read, 1); | ||
echo "\n"; | ||
$read[] = fpassthru($file_read); | ||
echo "\n"; | ||
print_r($read); | ||
|
||
echo "Read full file after rewind\n"; | ||
rewind($file_read); | ||
fpassthru($file_read); | ||
echo "\n"; | ||
|
||
echo "Test reading at file offsets\n"; | ||
$read = []; | ||
fseek($file_read, 10); | ||
$read[] = fpassthru($file_read, 5); | ||
echo "\n"; | ||
fseek($file_read, -5, SEEK_END); | ||
$read[] = fpassthru($file_read, 1); | ||
echo "\n"; | ||
fseek($file_read, -3, SEEK_END); | ||
$read[] = fpassthru($file_read, 1000); | ||
echo "\n"; | ||
$read[] = fpassthru($file_read); | ||
echo "\n"; | ||
print_r($read); | ||
|
||
echo "Test reading negative lengths\n"; | ||
$read = []; | ||
rewind($file_read); | ||
$read[] = fpassthru($file_read, -1); | ||
echo "\n"; | ||
rewind($file_read); | ||
$read[] = fpassthru($file_read, -2); | ||
echo "\n"; | ||
rewind($file_read); | ||
$read[] = fpassthru($file_read, -100); | ||
echo "\n"; | ||
rewind($file_read); | ||
$read[] = fpassthru($file_read, PHP_INT_MIN); | ||
echo "\n"; | ||
print_r($read); | ||
|
||
fclose($file_read); | ||
?> | ||
--EXPECT-- | ||
Test consecutive reads | ||
1 | ||
234 | ||
|
||
5 | ||
67890abcdefghijklmnopqrstuvwxyz | ||
Array | ||
( | ||
[0] => 1 | ||
[1] => 3 | ||
[2] => 0 | ||
[3] => 1 | ||
[4] => 31 | ||
) | ||
Read full file after rewind | ||
1234567890abcdefghijklmnopqrstuvwxyz | ||
Test reading at file offsets | ||
abcde | ||
v | ||
xyz | ||
|
||
Array | ||
( | ||
[0] => 5 | ||
[1] => 1 | ||
[2] => 3 | ||
[3] => 0 | ||
) | ||
Test reading negative lengths | ||
1234567890abcdefghijklmnopqrstuvwxyz | ||
1234567890abcdefghijklmnopqrstuvwxyz | ||
1234567890abcdefghijklmnopqrstuvwxyz | ||
1234567890abcdefghijklmnopqrstuvwxyz | ||
Array | ||
( | ||
[0] => 36 | ||
[1] => 36 | ||
[2] => 36 | ||
[3] => 36 | ||
) | ||
|
||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__."/passthru_with_length.tmp"); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.