Skip to content

Integrate stream filters into io.streams#359

Merged
thekid merged 4 commits intoxp-framework:mainfrom
thekid:feature/filter-streams
Mar 31, 2026
Merged

Integrate stream filters into io.streams#359
thekid merged 4 commits intoxp-framework:mainfrom
thekid:feature/filter-streams

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Mar 29, 2026

This pull request integrates with PHP's stream filters.

Example

Decode base64 from an input stream:

use io\streams\{MemoryInputStream, FilterInputStrem};

$encoded= base64_encode('Test');

$decode= new FilterInputStream(new MemoryInputStream($encoded), 'convert.base64-decode');
$decode->read(); // "Test"
$decode->close();

Performance

For smaller input, memory usage and time taken will be roughly the same:

$ cat README.md | base64 | xp base64.script.php - native
- => 3223 bytes (0.004 seconds, 1254.95 kB peak memory)

$ cat README.md | base64 | xp base64.script.php - streams
- => 3223 bytes (0.005 seconds, 1306.55 kB peak memory)

For larger files, significant performance improvements can be seen with this approach:

$ cat ../../composer.phar | base64 | xp base64.script.php - native
- => 1238154 bytes (0.236 seconds, 4322.32 kB peak memory)

$ cat ../../composer.phar | base64 | xp base64.script.php - streams
- => 1238154 bytes (0.029 seconds, 2514.55 kB peak memory)

See also

@thekid
Copy link
Copy Markdown
Member Author

thekid commented Mar 29, 2026

Would InputConversion and OutputConversion be better names for FilterInputStrem and FilterOutputStrem?

@thekid
Copy link
Copy Markdown
Member Author

thekid commented Mar 29, 2026

Would InputConversion and OutputConversion be better names for FilterInputStrem and FilterOutputStream?

What about InputConversion or InputTransformation?

Those are interesting but I'd lean against both, for a couple of reasons:

They don't read as streams. The rest of your API uses the InputStream/OutputStream suffix consistently, and these names break that pattern. Someone browsing the codebase would have a harder time recognising them as streams at a glance — InputConversion sounds more like a utility class or a value object describing a conversion operation.

They're nominalisations of the action, not descriptions of the thing. Conversion and Transformation describe what happens to the data, but the class is a stream — that's its primary identity. The name should reflect what it is first, and what it does second.

https://claude.ai/share/7ae14c8e-4766-4e68-b977-98d3ded47708

@thekid thekid merged commit c8a61a8 into xp-framework:main Mar 31, 2026
17 checks passed
@thekid thekid deleted the feature/filter-streams branch March 31, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant