Files
2022-09-20 03:10:03 +03:00

16 lines
414 B
JavaScript

import { Transform } from "stream";
// https://github.com/forscht/ddrive/blob/3.x/src/utils/asyncStreamProcessor.js
export class AsyncStreamProcessor extends Transform {
constructor(chunkProcessor) {
super();
this.chunkProcessor = chunkProcessor;
}
_transform(chunk, encoding, callback) {
this.chunkProcessor(chunk)
.then(() => callback(null))
.catch((err) => callback(err));
}
}