Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
it-to-stream
Advanced tools
Convert streaming iterables to Node.js streams
npm i it-to-stream
const toStream = require('it-to-stream')
// A streaming iterable "source" is just an (async) iterable
const source = (async function * () {
for (const value of [1, 2, 3, 4]) yield Buffer.from(value.toString())
})()
const readable = toStream.readable(source)
// Now we have a readable stream, we can consume it by
readable.on('data', console.log)
// or
readable.pipe(writable)
// or
pipeline(readable, writable, err => console.log(err || 'done'))
// A streaming iterable "sink" is an (async) function that takes a "source"
// and consumes it.
const sink = async source => {
for await (const chunk of source) {
console.log(chunk.toString())
}
}
const writable = toStream.writable(sink)
// Now we have a writable stream, we can pipe to it
fs.createReadStream('/path/to/file').pipe(writable)
// A streaming iterable "transform" is a function that takes a "source" and
// returns a "source".
const transform = source => (async function * () {
for await (const chunk of source) {
// Replace all space characters with dashes
yield Buffer.from(chunk.toString().replace(/ /g, '-'))
}
})()
const transform = toStream.transform(transform)
// Now we have a transform stream, we can pipe to and from it
fs.createReadStream('/path/to/file')
.pipe(transform)
.pipe(fs.createWriteStream('/path/to/file2'))
const toStream = require('it-to-stream')
toStream.readable(source, [options]): Readable
Convert a source iterable to a Readable
stream.
options
are passed directly to the Readable
constructor.
toStream.writable(sink, [options]): Writable
Convert a sink iterable to a Writable
stream.
options
are passed directly to the Writable
constructor.
toStream.transform(transform, [options]): Transform
Convert a transform iterable to a Transform
stream.
options
are passed directly to the Transform
constructor.
toStream.duplex(duplex, [options]): Duplex
Convert a duplex iterable to a Duplex
stream.
options
are passed directly to the Duplex
constructor.
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
FAQs
Convert streaming iterables to Node.js streams
We found that it-to-stream demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.