温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/stream/default/pipeline
点击访问原文链接

namespace pipeline | Node.js stream module | Bun

namespace pipeline | Node.js stream module | BunBuildDocsReferenceGuidesBlogDiscord/node:stream/default/pipelineNpipeline

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:stream/default/pipelineNpipeline

namespace

stream.default.pipeline { if (err) { console.error('Pipeline failed.', err); } else { console.log('Pipeline succeeded.'); } }, ); ``` The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streampipelinesource-transforms-destination-options). `stream.pipeline()` will call `stream.destroy(err)` on all streams except: * `Readable` streams which have emitted `'end'` or `'close'`. * `Writable` streams which have emitted `'finish'` or `'close'`. `stream.pipeline()` leaves dangling event listeners on the streams after the `callback` has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later. `stream.pipeline()` closes all the streams when an error is raised. The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below: ```js import fs from 'node:fs'; import http from 'node:http'; import { pipeline } from 'node:stream'; const server = http.createServer((req, res) => { const fileStream = fs.createReadStream('./fileNotExist.txt'); pipeline(fileStream, res, (err) => { if (err) { console.log(err); // No such file // this message can't be sent once `pipeline` already destroyed the socket return res.end('error!!!'); } }); }); ```" data-algolia-static="false" data-algolia-merged="true" data-type="Namespace">function pipelineS extends PipelineSourceany>, D extends WritableStream | WritableStreamany> | TransformStreamany, any> | WritableStreamstring | BufferArrayBufferLike>> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineDestinationFunctionReadableStream, any> | PipelineDestinationFunctionReadableStreamany>, any> | PipelineDestinationFunctionTransformStreamany, any>, any> | PipelineDestinationFunctionIterableany, any, any>, any> | PipelineDestinationFunctionAsyncIterableany, any, any>, any> | PipelineDestinationFunctionPipelineSourceFunctionany>, any>>(source: S,destination: D,callback: PipelineCallbackD>): PipelineResultD>;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipelineS extends PipelineSourceany>, T extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorReadableStream, any> | PipelineTransformGeneratorReadableStreamany>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorIterableany, any, any>, any> | PipelineTransformGeneratorAsyncIterableany, any, any>, any> | PipelineTransformGeneratorPipelineSourceFunctionany>, any>, D extends WritableStream | WritableStreamany> | TransformStreamany, any> | WritableStreamstring | BufferArrayBufferLike>> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineDestinationFunctionTransformStreamany, any>, any> | PipelineDestinationFunctionReadWriteStream, any> | PipelineDestinationFunctionTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorReadableStream, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorReadableStreamany>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorIterableany, any, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>>(source: S,transform: T,destination: D,callback: PipelineCallbackD>): PipelineResultD>;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipelineS extends PipelineSourceany>, T1 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorReadableStream, any> | PipelineTransformGeneratorReadableStreamany>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorIterableany, any, any>, any> | PipelineTransformGeneratorAsyncIterableany, any, any>, any> | PipelineTransformGeneratorPipelineSourceFunctionany>, any>, T2 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, D extends WritableStream | WritableStreamany> | TransformStreamany, any> | WritableStreamstring | BufferArrayBufferLike>> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineDestinationFunctionTransformStreamany, any>, any> | PipelineDestinationFunctionReadWriteStream, any> | PipelineDestinationFunctionTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>>(source: S,transform1: T1,transform2: T2,destination: D,callback: PipelineCallbackD>): PipelineResultD>;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipelineS extends PipelineSourceany>, T1 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorReadableStream, any> | PipelineTransformGeneratorReadableStreamany>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorIterableany, any, any>, any> | PipelineTransformGeneratorAsyncIterableany, any, any>, any> | PipelineTransformGeneratorPipelineSourceFunctionany>, any>, T2 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, T3 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>, D extends WritableStream | WritableStreamany> | TransformStreamany, any> | WritableStreamstring | BufferArrayBufferLike>> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineDestinationFunctionTransformStreamany, any>, any> | PipelineDestinationFunctionReadWriteStream, any> | PipelineDestinationFunctionTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>, any>>(source: S,transform1: T1,transform2: T2,transform3: T3,destination: D,callback: PipelineCallbackD>): PipelineResultD>;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipelineS extends PipelineSourceany>, T1 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorReadableStream, any> | PipelineTransformGeneratorReadableStreamany>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorIterableany, any, any>, any> | PipelineTransformGeneratorAsyncIterableany, any, any>, any> | PipelineTransformGeneratorPipelineSourceFunctionany>, any>, T2 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, T3 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>, T4 extends ReadWriteStream | TransformStreamany, any> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineTransformGeneratorTransformStreamany, any>, any> | PipelineTransformGeneratorReadWriteStream, any> | PipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any>, any> | PipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>, any>, D extends WritableStream | WritableStreamany> | TransformStreamany, any> | WritableStreamstring | BufferArrayBufferLike>> | TransformStreamstring | BufferArrayBufferLike>, any> | PipelineDestinationFunctionTransformStreamany, any>, any> | PipelineDestinationFunctionReadWriteStream, any> | PipelineDestinationFunctionTransformStreamstring | BufferArrayBufferLike>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamany, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorReadWriteStream, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadWriteStream, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamstring | BufferArrayBufferLike>, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStream, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorReadableStreamany>, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorTransformStreamany, any>, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorIterableany, any, any>, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorAsyncIterableany, any, any>, any>, any>, any>, any>, any> | PipelineDestinationFunctionPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineTransformGeneratorPipelineSourceFunctionany>, any>, any>, any>, any>, any>>(source: S,transform1: T1,transform2: T2,transform3: T3,transform4: T4,destination: D,callback: PipelineCallbackD>): PipelineResultD>;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipeline(streams: readonly WritableStream | PipelineSourceany> | PipelineTransformStreamsunknown, any> | PipelineTransformGeneratorany, any> | WritableStreamunknown> | PipelineDestinationFunctionany, any>[],callback: (err: null | ErrnoException) => void): WritableStream;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
@param callback

Called when the pipeline is fully done.

function pipeline(...streams: [PipelineSourceany>, ...PipelineTransformStreamsunknown, any> | PipelineTransformGeneratorany, any>[], WritableStream | TransformStreamunknown, any> | WritableStreamunknown> | PipelineDestinationFunctionany, any>, callback: (err: null | ErrnoException) => void]): WritableStream;

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

import { pipeline } from 'node:stream';
import fs from 'node:fs';
import zlib from 'node:zlib';

// Use the pipeline API to easily pipe a series of streams
// together and get notified when the pipeline is fully done.

// A pipeline to gzip a potentially huge tar file efficiently:

pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
},
);

The pipeline API provides a promise version.

stream.pipeline() will call stream.destroy(err) on all streams except:

Readable streams which have emitted 'end' or 'close'.Writable streams which have emitted 'finish' or 'close'.

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. If the last stream is readable, dangling event listeners will be removed so that the last stream can be consumed later.

stream.pipeline() closes all the streams when an error is raised. The IncomingRequest usage with pipeline could lead to an unexpected behavior once it would destroy the socket without sending the expected response. See the example below:

import fs from 'node:fs';
import http from 'node:http';
import { pipeline } from 'node:stream';

const server = http.createServer((req, res) => {
const fileStream = fs.createReadStream('./fileNotExist.txt');
pipeline(fileStream, res, (err) => {
if (err) {
console.log(err); // No such file
// this message can't be sent once `pipeline` already destroyed the socket
return res.end('error!!!');
}
});
});
namespace pipeline

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

namespace pipeline | Node.js stream module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for namespace node:stream.default.pipeline | Bun