-
Notifications
You must be signed in to change notification settings - Fork 8k
Stream filter seeking #19981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bukka
wants to merge
19
commits into
php:master
Choose a base branch
from
bukka:stream_filter_seeking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Stream filter seeking #19981
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f528edd
stream: implement initial changes to control filter seeking
bukka 43695c6
stream: break current streams API for cleaner design
bukka 102dde8
stream: add filter seek support to user filter
bukka 5351f74
stream: add filter seek support to standard filters
bukka 22279ac
stream: add filter seek support to iconv filter
bukka 678840f
stream: add filter seek support to zlib filters
bukka 2ddf202
stream: add filter seek support to bz2 filters
bukka 2587be3
stream: add missing php_user_filter::seek implementation
bukka b0bd357
stream: fix new filter factory create signature
bukka c35b37e
stream: use seekable filter for bug 79945 test
bukka e6ecdcb
stream: add test for bz2 filter seeking
bukka 83d44b7
stream: add tests and fix zlib filter seeking
bukka 33a6902
stream: add test for iconv filter seeking
bukka bb66851
stream: test string filters seeking
bukka 0fa736c
stream: test convert filters seeking
bukka ecd7c90
stream: add tests and fix user filter seeking
bukka f6f6152
stream: add filter seekable enum and other fixes
bukka 7527cd6
stream: optimize filter seek method call
bukka 4d5362e
stream: improve filter seeking warning and address some nits
bukka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,55 @@ | ||
| --TEST-- | ||
| bzip2.compress filter with seek to start | ||
| --EXTENSIONS-- | ||
| bz2 | ||
| --FILE-- | ||
| <?php | ||
| $file = __DIR__ . '/bz2_filter_seek_compress.bz2'; | ||
|
|
||
| $text1 = 'Short text.'; | ||
| $text2 = 'This is a much longer text that will completely overwrite the previous compressed data in the file.'; | ||
|
|
||
| $fp = fopen($file, 'w+'); | ||
| stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE); | ||
|
|
||
| fwrite($fp, $text1); | ||
| fflush($fp); | ||
|
|
||
| $size1 = ftell($fp); | ||
| echo "Size after first write: $size1\n"; | ||
|
|
||
| $result = fseek($fp, 0, SEEK_SET); | ||
| echo "Seek to start: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| fwrite($fp, $text2); | ||
| fflush($fp); | ||
|
|
||
| $size2 = ftell($fp); | ||
| echo "Size after second write: $size2\n"; | ||
| echo "Second write is larger: " . ($size2 > $size1 ? "YES" : "NO") . "\n"; | ||
|
|
||
| $result = fseek($fp, 50, SEEK_SET); | ||
| echo "Seek to middle: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| fclose($fp); | ||
|
|
||
| $fp = fopen($file, 'r'); | ||
| stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_READ); | ||
| $content = stream_get_contents($fp); | ||
| fclose($fp); | ||
|
|
||
| echo "Decompressed content matches text2: " . ($content === $text2 ? "YES" : "NO") . "\n"; | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| @unlink(__DIR__ . '/bz2_filter_seek_compress.bz2'); | ||
| ?> | ||
| --EXPECTF-- | ||
| Size after first write: 40 | ||
| Seek to start: SUCCESS | ||
| Size after second write: 98 | ||
| Second write is larger: YES | ||
|
|
||
| Warning: fseek(): Stream filter bzip2.compress is seekable only to start position in %s on line %d | ||
| Seek to middle: FAILURE | ||
| Decompressed content matches text2: YES |
This file contains hidden or 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,43 @@ | ||
| --TEST-- | ||
| bzip2.decompress filter with seek to start | ||
| --EXTENSIONS-- | ||
| bz2 | ||
| --FILE-- | ||
| <?php | ||
| $file = __DIR__ . '/bz2_filter_seek_decompress.bz2'; | ||
|
|
||
| $text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.'; | ||
|
|
||
| $fp = fopen($file, 'w'); | ||
| stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE); | ||
| fwrite($fp, $text); | ||
| fclose($fp); | ||
|
|
||
| $fp = fopen($file, 'r'); | ||
| stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_READ); | ||
|
|
||
| $partial = fread($fp, 20); | ||
| echo "First read (20 bytes): " . $partial . "\n"; | ||
|
|
||
| $result = fseek($fp, 0, SEEK_SET); | ||
| echo "Seek to start: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| $full = stream_get_contents($fp); | ||
| echo "Content after seek matches: " . ($full === $text ? "YES" : "NO") . "\n"; | ||
|
|
||
| $result = fseek($fp, 50, SEEK_SET); | ||
| echo "Seek to middle: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| fclose($fp); | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| @unlink(__DIR__ . '/bz2_filter_seek_decompress.bz2'); | ||
| ?> | ||
| --EXPECTF-- | ||
| First read (20 bytes): I am the very model | ||
| Seek to start: SUCCESS | ||
| Content after seek matches: YES | ||
|
|
||
| Warning: fseek(): Stream filter bzip2.decompress is seekable only to start position in %s on line %d | ||
| Seek to middle: FAILURE |
This file contains hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| --TEST-- | ||
| iconv stream filter with seek to start | ||
| --EXTENSIONS-- | ||
| iconv | ||
| --FILE-- | ||
| <?php | ||
| $file = __DIR__ . '/iconv_stream_filter_seek.txt'; | ||
|
|
||
| $text = 'Hello, this is a test for iconv stream filter seeking functionality.'; | ||
|
|
||
| $fp = fopen($file, 'w'); | ||
| stream_filter_append($fp, 'convert.iconv.ISO-2022-JP/UTF-8'); | ||
| fwrite($fp, $text); | ||
| fclose($fp); | ||
|
|
||
| $fp = fopen($file, 'r'); | ||
| stream_filter_append($fp, 'convert.iconv.UTF-8/ISO-2022-JP'); | ||
|
|
||
| $partial = fread($fp, 20); | ||
| echo "First read (20 bytes): " . $partial . "\n"; | ||
|
|
||
| $result = fseek($fp, 0, SEEK_SET); | ||
| echo "Seek to start: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| $full = fread($fp, strlen($text)); | ||
| echo "Content after seek matches: " . ($full === $text ? "YES" : "NO") . "\n"; | ||
|
|
||
| $result = fseek($fp, 50, SEEK_SET); | ||
| echo "Seek to middle: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n"; | ||
|
|
||
| fclose($fp); | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| @unlink(__DIR__ . '/iconv_stream_filter_seek.txt'); | ||
| ?> | ||
| --EXPECTF-- | ||
| First read (20 bytes): Hello, this is a tes | ||
| Seek to start: SUCCESS | ||
| Content after seek matches: YES | ||
|
|
||
| Warning: fseek(): Stream filter convert.iconv.* is seekable only to start position in %s on line %d | ||
| Seek to middle: FAILURE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.