![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
drain an object stream and wrap it in a promise
Think of it as a streaming version of Q.all. Pipe a stream of promises into it and await them all to resolve, or reject on any error.
var charybdis = require('charybdis')
var readStream = // from somewhere
var done = charybdis(readStream, function (obj) {
// this is called for each object in the readStream
return Promise(obj)
})
done.then(function (stats) {
console.log('we just processed ' + stats.operations + ' ops')
})
In pseudo code, lets say we want to stream a log file and validate a resource in the db:
read(logfile)
.pipe(parseLog)
.pipe(charybdis(validateLogEntry))
.then(function () { console.log('done')},
function (err) { console.error(err)})
charybdis := (handler?: (Object) => Promise))
=> WriteStream & Promise<Stats>
type Stats : {
objects: Number,
operations: Number,
start: Timestamp,
streamEnd: Timestamp,
end: Timestamp
}
emits:
inEnd: Event<void> when the ReadStream ends
tick: Event<Stats> periodically as processing is happening
resolves:
when each of the promises is resolved
rejected:
when any of of the promises is rejected or on stream error
The promiser
is a function called on every item in the read stream.
If it returns a Promise
, that is considered to be an operation.
Once all input streams have ended and all operations have been resolved,
the aggregate promise will be resolved.
$ npm install charybdis
From package root:
$ npm install
$ npm test
MIT. (c) MMXIII AgileMD hello@agilemd.com. See LICENSE.md
FAQs
drain an object stream and wrap it in a promise
The npm package charybdis receives a total of 5 weekly downloads. As such, charybdis popularity was classified as not popular.
We found that charybdis 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.