UNPKG

streams

Version:

A lazy streams library for functional composition in JavaScript.

26 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readableChunks = readableChunks; const node_stream_1 = require("node:stream"); async function* readableChunks(readable, encoding) { const passThrough = new node_stream_1.PassThrough(); if (encoding !== undefined) { passThrough.setEncoding(encoding); } // Pipe to a PassThrough duplex stream so as not to destroy the Readable // stream when the AsyncGenerator is terminated. This allows te Readable // stream to be used again after the AsyncGenerator has completed. readable.pipe(passThrough); try { yield* passThrough; } finally { // Detach from the Readable stream to release it so it is not potentially // holding up the node process. Note that unpipe is not called automatically // when the PassThrough stream that is piped to it is destroyed. This is an // observed behavior, which is not specified in the Node.js Streams // documentation. readable.unpipe(passThrough); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhZGFibGUtY2h1bmtzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3NvdXJjZXMvcmVhZGFibGUtY2h1bmtzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEsd0NBd0JDO0FBMUJELDZDQUFvRDtBQUU3QyxLQUFLLFNBQVMsQ0FBQyxDQUFDLGNBQWMsQ0FDbkMsUUFBa0IsRUFDbEIsUUFBeUI7SUFFekIsTUFBTSxXQUFXLEdBQUcsSUFBSSx5QkFBVyxFQUFFLENBQUM7SUFFdEMsSUFBSSxRQUFRLEtBQUssU0FBUyxFQUFFLENBQUM7UUFDM0IsV0FBVyxDQUFDLFdBQVcsQ0FBQyxRQUFRLENBQUMsQ0FBQztJQUNwQyxDQUFDO0lBRUQsd0VBQXdFO0lBQ3hFLHdFQUF3RTtJQUN4RSxrRUFBa0U7SUFDbEUsUUFBUSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUMzQixJQUFJLENBQUM7UUFDSCxLQUFLLENBQUMsQ0FBQyxXQUFXLENBQUM7SUFDckIsQ0FBQztZQUFTLENBQUM7UUFDVCx5RUFBeUU7UUFDekUsNEVBQTRFO1FBQzVFLDJFQUEyRTtRQUMzRSxtRUFBbUU7UUFDbkUsaUJBQWlCO1FBQ2pCLFFBQVEsQ0FBQyxNQUFNLENBQUMsV0FBVyxDQUFDLENBQUM7SUFDL0IsQ0FBQztBQUNILENBQUMifQ==