Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @sounisi5011/stream-transform-from with all npm packages installed. Try it out:

const stream = require('stream'); const { transformFrom } = require('@sounisi5011/stream-transform-from'); stream.pipeline( stream.Readable.from([1, 2, 3, 4, 5]), // Convert a number to a Buffer object. transformFrom( async function*(source) { for await (const { chunk: inputChunk } of source) { console.log({ inputChunk }); if (typeof inputChunk === 'number') { const code = inputChunk; yield Buffer.from([code]); } } }, { writableObjectMode: true }, ), // Transform a Buffer object. transformFrom(async function*(source) { for await (const { chunk } of source) { yield Buffer.concat([ Buffer.from([0xF0]), chunk, Buffer.from([0xFF]), ]); } }), new stream.Writable({ write(outputChunk, _, done) { console.log({ outputChunk }); done(); }, }), error => { if (error) { console.error(error); } else { console.log('done!'); } }, );

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@sounisi5011/stream-transform-from v1.1.1

Create a transform stream from an async iterator

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free