mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
92971d3c87
* Update eslint-plugin-import version * Convert JS files to use ESM * Update ESLint rules to check imports * Fix test:unit:global command env * Cleanup mock-dev script
24 lines
620 B
JavaScript
24 lines
620 B
JavaScript
import { Writable as WritableStream } from 'readable-stream'
|
|
import promiseToCallback from 'promise-to-callback'
|
|
|
|
class AsyncWritableStream extends WritableStream {
|
|
|
|
constructor (asyncWriteFn, _opts) {
|
|
const opts = Object.assign({ objectMode: true }, _opts)
|
|
super(opts)
|
|
this._asyncWriteFn = asyncWriteFn
|
|
}
|
|
|
|
// write from incomming stream to state
|
|
_write (chunk, encoding, callback) {
|
|
promiseToCallback(this._asyncWriteFn(chunk, encoding))(callback)
|
|
}
|
|
|
|
}
|
|
|
|
function createStreamSink (asyncWriteFn, _opts) {
|
|
return new AsyncWritableStream(asyncWriteFn, _opts)
|
|
}
|
|
|
|
export default createStreamSink
|