Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
stream-to-it
Advanced tools
Convert Node.js streams to streaming iterables
npm i stream-to-it
const toIterable = require('stream-to-it')
const readable = fs.createReadStream('/path/to/file')
// Node.js streams are already async iterable so this is just s => s
const source = toIterable.source(readable)
for await (const chunk of source) {
console.log(chunk.toString())
}
const pipe = require('it-pipe')
const source = [Buffer.from('Hello '), Buffer.from('World!')]
const sink = toIterable.sink(fs.createWriteStream('/path/to/file'))
await pipe(source, sink)
const { Transform } = require('stream')
const output = await pipe(
[true, false, true, true],
toIterable.transform(new Transform({ // Inverter transform :)
transform (chunk, enc, cb) {
cb(null, !chunk)
}
})),
// Collect and return the chunks
source => {
const chunks = []
for await (chunk of source) chunks.push(chunk)
return chunks
}
)
console.log(output) // [ false, true, false, false ]
const toIterable = require('stream-to-it')
toIterable.source(stream): Function
Convert a Readable
stream to a source iterable.
toIterable.sink(sink): Function
Convert a Writable
stream to a sink iterable.
toIterable.transform(transform): Function
Convert a Transform
stream to a transform iterable.
toIterable.duplex(duplex): { sink: Function, source: Function }
Convert a Duplex
stream to a duplex iterable.
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
FAQs
Convert Node.js streams to streaming iterables
The npm package stream-to-it receives a total of 0 weekly downloads. As such, stream-to-it popularity was classified as not popular.
We found that stream-to-it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.