- From: Domenic Denicola <notifications@github.com>
- Date: Sat, 19 Aug 2017 19:31:37 +0000 (UTC)
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/765/323543213@github.com>
So the basic problem is that manually creating a transform stream is very hard. You may enjoy looking through https://github.com/whatwg/streams/blob/master/reference-implementation/lib/transform-stream.js, which we're attempting to clean up and eventually standardize and ship. When it's ready, you'll be able to create something simple like ```js const { readable, writable } = new TransformStream({ transform(chunk) { return chunk.map(c => c * 10); } }); ``` Until then, properly understanding how to get data from the writable side to the readable side of a transform is tricky. Your version has a variety of bugs, but even after I cleaned them up, it turns out it doesn't work, because pull() is called when there is no chunk written to the writable side, and is not called after that, so it never makes it to the readable side. Here is a demo if this not working well: http://jsbin.com/yowoqozavo/1/edit?html,console Here is a version that works, using a very different technique: http://jsbin.com/hicawawizo/edit?html,console I don't really recommend manually creating transform streams yourself. Manually creating { readable, writable } pairs makes sense for some cases, known as "duplex" streams, where there are two separate I/O channels: see e.g. https://streams.spec.whatwg.org/#example-both. But for transformations of data, you'll really want to use transform-stream.js, and eventually, the browser's built-in TransformStream. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/streams/issues/765#issuecomment-323543213
Received on Saturday, 19 August 2017 19:31:59 UTC