From the through2 documentation:
Do you need this?
Since Node.js introduced Simplified Stream Construction, many uses of through2 have become redundant. Consider whether you really need to use through2 or just want to use the 'readable-stream' package, or the core 'stream' package (which is derived from 'readable-stream').
If I understand correctly, now (from 2021) we can intervene to the streams without third-party libraries.
I did not found how to do same thing as through2
in Stream documentation.
// ...
.pipe(through2(function (file, encoding, callback) {
// Do something with file ...
callback(null, file)
}))
// ↑ Possible to reach the same effect natively (with core packages)?
I suppose, for 2021 there must be some method supporting async/await syntax:
// ...
.pipe(newFeatureOfModernNodeJS(async function (file) {
await doSomethingAsyncWithFile(file);
// on fail - same effect as "callback(new Error('...'))" of trough2
return file; // same effect as "callback(null, file)" of trough2
// or
return null; // same effect as `callback()` of trough2
}))
// ↑ Possible to reach the same effect natively (with core packages)?