Comments (9)
If implementing new streams is complicated, maybe some work should be put into a simpler API that's promise based instead of event based? There could then be a new stream implementation, that makes these simpler implementations work with the existing stream API.
from stream.
Don't misunderstand me. When I say complicated I mean that there are some specific parts that you should take into account once and again (event propagation, some checks before writing...). When I create a new class in my codebase I need to test it and testing the same feature for all my Streams transformers, even if it's the same, doesn't make sense IMO.
The fast and easy way of doing that would be to create by myself a copy of ThroughStream and doing these changes, but I think that would be interesting to make something available for everyone.
from stream.
Take a look at these streams @mmoreram https://github.com/WyriHaximus/reactphp-stream-base64/tree/master/src If the only thing you need is data transformation that should show we'd you need
from stream.
@WyriHaximus Seems like https://github.com/WyriHaximus/reactphp-stream-base64/blob/af6d98b72850aaf220e6ec28d7c4c788973ed3b9/src/ReadableStreamBase64Encode.php#L56 pipes the original stream instead of the transformed stream?
from stream.
@WyriHaximus but these examples are storing the whole data set in memory, right? At least until you close the stream?
from stream.
@mmoreram only, only what they need to transform the next chunk of data, once they encode/decode that chunk it's released from memory again.
from stream.
@WyriHaximus I've created this PR.
TBH, I don't like so much the name "TransformerStream", but I didn't find a better one.
For the implementation, I took as reference the NDJson
encoder. An abstraction of what a transformer should always seem a good thing for the final user.
from stream.
@kelunik thanks just fixed them 👍
from stream.
@mmoreram Thanks for bringing up this discussion!
It's my understanding opening the ThroughStream
for extension is not a good idea because it breaks the existing encapsulation. This class specifically exists for 1-on-1 mapping from input to output.
If you want to implement custom streaming behavior, you can always implement the DuplexStreamInterface
. Depending on your specific use case, it might also be easier to implement just the ReadableStreamInterface
or WritableStreamInterface
. This allows you to implement any kind of custom behavior, such as data transformations, time-based forwarding and much more.
You can take a look at https://packanalyst.com/class?q=React\Stream\ReadableStreamInterface and others for some possible implementation ideas. It's my understanding this covers all possible use cases and implementing this interface shouldn't be too hard imho.
I hope this helps 👍
I'm closing this for now as it hasn't received any input in a while and I believe this has been answered. Please come back with more details if this problem persists and we can always reopen this 👍
from stream.
Related Issues (20)
- Test failures on OSX HOT 3
- unable to set stream resource to non-blocking - PHP 7.1 stream_set_blocking doesn't work HOT 6
- Unable to write to stream: fwrite(): send of 8192 bytes failed with errno=32 Broken pipe HOT 2
- end event from pipes doesn't forward $data HOT 3
- How to clear console with stream HOT 6
- Consider not throwing exception if stream cannot be set to non-blocking mode HOT 6
- Unable to write to stream: fwrite(): send of XXX bytes failed with errno=32 Broken pipe HOT 2
- [Question] Asynchronous I/O HOT 1
- ReadableStreamInterface to PSR-7 StreamInterface. HOT 2
- Is stream reads resource only once? HOT 1
- "Always on" connection that streams data "bundles" HOT 2
- PHP 7.4 in the test-suite
- Code working on *nix silently failing on Windows HOT 10
- Stream data into multiple CSV files and stream a ZIP file with these HOT 2
- Unable to set stream resource to non-blocking mode [not STDIN or STDOUT] HOT 5
- Roadmap to reactphp/stream v3 HOT 2
- Unclear semantics of write() in WritableStreamInterface HOT 5
- Closed STDIN returns endless stream of random data HOT 11
- Is 'close' a suitable name for that method? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stream.