From a43c64399a7162b25bf6bd3f26dad51ffcc0b0d4 Mon Sep 17 00:00:00 2001
From: djfdyuruiry =e;n--){var r=this.uncheckedNodes[n],i=r.child.toString();i in this.minimizedNodes?r.parent.edges[r.char]=this.minimizedNodes[i]:(r.child._str=i,this.minimizedNodes[i]=r.child),this.uncheckedNodes.pop()}};t.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},t.Index.prototype.search=function(e){return this.query(function(n){var r=new t.QueryParser(e,n);r.parse()})},t.Index.prototype.query=function(e){for(var n=new t.Query(this.fields),r=Object.create(null),i=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),c=0;c=e;n--){var r=this.uncheckedNodes[n],i=r.child.toString();i in this.minimizedNodes?r.parent.edges[r.char]=this.minimizedNodes[i]:(r.child._str=i,this.minimizedNodes[i]=r.child),this.uncheckedNodes.pop()}};t.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},t.Index.prototype.search=function(e){return this.query(function(n){var r=new t.QueryParser(e,n);r.parse()})},t.Index.prototype.query=function(e){for(var n=new t.Query(this.fields),r=Object.create(null),i=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),c=0;c
import { AsyncResource, executionAsyncId } from 'node:async_hooks';
// AsyncResource() is meant to be extended. Instantiating a
// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
// async_hook.executionAsyncId() is used.
const asyncResource = new AsyncResource(
type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
);
// Run a function in the execution context of the resource. This will
// * establish the context of the resource
// * trigger the AsyncHooks before callbacks
// * call the provided function `fn` with the supplied arguments
// * trigger the AsyncHooks after callbacks
// * restore the original execution context
asyncResource.runInAsyncScope(fn, thisArg, ...args);
// Call AsyncHooks destroy callbacks.
asyncResource.emitDestroy();
// Return the unique ID assigned to the AsyncResource instance.
asyncResource.asyncId();
// Return the trigger ID for the AsyncResource instance.
asyncResource.triggerAsyncId();
-Adds a rule to block the given IP address.
An IPv4 or IPv6 address.
Optionaltype: IPVersionEither 'ipv4' or 'ipv6'.
Adds a rule to block the given IP address.
+Adds a rule to block the given IP address.
An IPv4 or IPv6 address.
Adds a rule to block a range of IP addresses from start (inclusive) toend (inclusive).
Adds a rule to block a range of IP addresses from start (inclusive) toend (inclusive).
The starting IPv4 or IPv6 address in the range.
The ending IPv4 or IPv6 address in the range.
Optionaltype: IPVersionEither 'ipv4' or 'ipv6'.
Adds a rule to block a range of IP addresses from start (inclusive) toend (inclusive).
Adds a rule to block a range of IP addresses from start (inclusive) toend (inclusive).
The starting IPv4 or IPv6 address in the range.
The ending IPv4 or IPv6 address in the range.
Adds a rule to block a range of IP addresses specified as a subnet mask.
+Adds a rule to block a range of IP addresses specified as a subnet mask.
The network IPv4 or IPv6 address.
The number of CIDR prefix bits. For IPv4, this must be a value between 0 and 32. For IPv6, this must be between 0 and 128.
Adds a rule to block a range of IP addresses specified as a subnet mask.
+Adds a rule to block a range of IP addresses specified as a subnet mask.
The network IPv4 or IPv6 address.
The number of CIDR prefix bits. For IPv4, this must be a value between 0 and 32. For IPv6, this must be between 0 and 128.
Optionaltype: IPVersionEither 'ipv4' or 'ipv6'.
Returns true if the given IP address matches any of the rules added to theBlockList.
Returns true if the given IP address matches any of the rules added to theBlockList.
const blockList = new net.BlockList();
blockList.addAddress('123.123.123.123');
blockList.addRange('10.0.0.1', '10.0.0.10');
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
console.log(blockList.check('123.123.123.123')); // Prints: true
console.log(blockList.check('10.0.0.3')); // Prints: true
console.log(blockList.check('222.111.111.222')); // Prints: false
// IPv6 notation for IPv4 addresses works:
console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
The IP address to check
Returns true if the given IP address matches any of the rules added to theBlockList.
Returns true if the given IP address matches any of the rules added to theBlockList.
const blockList = new net.BlockList();
blockList.addAddress('123.123.123.123');
blockList.addRange('10.0.0.1', '10.0.0.10');
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
console.log(blockList.check('123.123.123.123')); // Prints: true
console.log(blockList.check('10.0.0.3')); // Prints: true
console.log(blockList.check('222.111.111.222')); // Prints: false
// IPv6 notation for IPv4 addresses works:
console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
The IP address to check
Optionaltype: IPVersionEither 'ipv4' or 'ipv6'.
Experimentalconst blockList = new net.BlockList();
const data = [
'Subnet: IPv4 192.168.1.0/24',
'Address: IPv4 10.0.0.5',
'Range: IPv4 192.168.2.1-192.168.2.10',
'Range: IPv4 10.0.0.1-10.0.0.10',
];
blockList.fromJSON(data);
blockList.fromJSON(JSON.stringify(data));
+Experimentalconst blockList = new net.BlockList();
const data = [
'Subnet: IPv4 192.168.1.0/24',
'Address: IPv4 10.0.0.5',
'Range: IPv4 192.168.2.1-192.168.2.10',
'Range: IPv4 10.0.0.1-10.0.0.10',
];
blockList.fromJSON(data);
blockList.fromJSON(JSON.stringify(data));
StaticisReturns true if the value is a net.BlockList.
StaticisReturns true if the value is a net.BlockList.
Any JS value
code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'.
Content-Length value should be in bytes, not characters. Use Buffer.byteLength() to determine the length of the body in bytes.
Optional_Optional_Optional[captureMarks the request as aborting. Calling this will cause remaining data +
Optional[captureMarks the request as aborting. Calling this will cause remaining data in the response to be dropped and the socket to be destroyed.
Since v14.1.0,v13.14.0 - Use destroy instead.
writable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
stream has ended and subsequent calls to write() or end() will result in
an ERR_STREAM_DESTROYED error.
This is a destructive and immediate way to destroy a stream. Previous calls to write() may not have drained, and may trigger an ERR_STREAM_DESTROYED error.
@@ -258,23 +258,14 @@
but instead implement writable._destroy().
Optionalerror: ErrorOptional, an error to emit with 'error' event.
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
+
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -404,10 +395,10 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
Sets a single header value. If the header already exists in the to-be-sent +
Sets a single header value. If the header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings to send multiple headers with the same name.
Header name
@@ -459,7 +450,7 @@See also: writable.cork().
The writable.write() method writes some data to the stream, and calls the
+
The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
@@ -495,44 +486,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
diff --git a/docs/classes/_internal_.Collection.html b/docs/classes/_internal_.Collection.html
index 82777159..1a0ef7fa 100644
--- a/docs/classes/_internal_.Collection.html
+++ b/docs/classes/_internal_.Collection.html
@@ -1,4 +1,4 @@
-
AbstractAbstractThe EventEmitterAsyncResource class has the same methods and takes the
same options as EventEmitter and AsyncResource themselves.
'removeListener' when existing listeners are removed.
It supports the following option:
AbstractAbstractThis class serves as the parent class of ClientRequest and ServerResponse. It is an abstract outgoing message from the perspective of the participants of an HTTP transaction.
Optional_Optional_Optional[captureEvent emitter +
Optional[captureEvent emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Adds HTTP trailers (headers but at the end of the message) to the message.
+Adds HTTP trailers (headers but at the end of the message) to the message.
Trailers will only be emitted if the message is chunked encoded. If not, the trailers will be silently discarded.
HTTP requires the Trailer header to be sent to emit trailers,
@@ -255,7 +255,7 @@
to be processed. However, use of writable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
stream has ended and subsequent calls to write() or end() will result in
an ERR_STREAM_DESTROYED error.
This is a destructive and immediate way to destroy a stream. Previous calls to write() may not have drained, and may trigger an ERR_STREAM_DESTROYED error.
@@ -267,23 +267,14 @@
but instead implement writable._destroy().
Optionalerror: ErrorOptional, an error to emit with 'error' event.
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
+
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -377,7 +368,7 @@
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -390,7 +381,7 @@
The callback function
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
+
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -408,7 +399,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Returns a copy of the array of listeners for the event named eventName,
+
Returns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
@@ -453,10 +444,10 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
Sets a single header value. If the header already exists in the to-be-sent +
Sets a single header value. If the header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings to send multiple headers with the same name.
Header name
@@ -503,7 +494,7 @@See also: writable.cork().
The writable.write() method writes some data to the stream, and calls the
+
The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
@@ -539,44 +530,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
diff --git a/docs/classes/_internal_.Readable.html b/docs/classes/_internal_.Readable.html
index 0a30e9a5..90ac9dc3 100644
--- a/docs/classes/_internal_.Readable.html
+++ b/docs/classes/_internal_.Readable.html
@@ -1,5 +1,5 @@
Readonly[OptionaladdCustomize the way that a key-value pair is resolved. Used for YAML 1.1 !!merge << handling.
OptionalanchorAn optional anchor on this node. Used by alias nodes.
OptionalcommentA comment on or immediately after this
@@ -25,17 +25,19 @@OptionalformatBy default (undefined), numbers use decimal notation. The YAML 1.2 core schema only supports 'HEX' and 'OCT'. The YAML 1.1 schema also supports 'BIN' and 'TIME'
-OptionalminIf value is a number, use this value when stringifying this node.
OptionalrangeThe [start, value-end, node-end] character offsets for the part of the
+
OptionalminIf value is a number that is serialized as a decimal string
+(i.e. not using exponential notation),
+use this value when stringifying this node.
OptionalrangeThe [start, value-end, node-end] character offsets for the part of the
source parsed into this node (undefined if not parsed). The value-end
and node-end positions are themselves not included in their respective
ranges.
OptionalsourceSet during parsing to the source string value
-OptionalspaceA blank line before this node and its commentBefore
+OptionalspaceA blank line before this node and its commentBefore
OptionalsrcThe CST token that was composed into this node.
OptionaltagA fully qualified tag, if required
OptionaltypeThe scalar style used for the node's string representation
-Create a copy of this node.
+Create a copy of this node.
A plain JavaScript representation of this node.
Optional__namedParameters: ToJSOptionsA plain JS representation of this node
-Optionalarg: anyOptionalctx: ToJSContextOptionalarg: anyOptionalctx: ToJSContext'connection' event emitted on a Server, so the user can use
it to interact with the client.
This can be changed manually to change the half-open behavior of an existing
Duplex stream instance, but must be changed before the 'end' event is emitted.
ReadonlyautoThis property is only present if the family autoselection algorithm is enabled in socket.connect(options)
+
ReadonlyautoThis property is only present if the family autoselection algorithm is enabled in socket.connect(options)
and it is an array of the addresses that have been attempted.
Each address is a string in the form of $IP:$PORT.
If the connection was successful, then the last address is the one that the socket is currently connected to.
ReadonlybufferThis property shows the number of characters buffered for writing. The buffer +
ReadonlybufferThis property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer.
net.Socket has the property that socket.write() always works. This is to
@@ -146,32 +146,32 @@
"throttle" the data flows in their program with socket.pause() and socket.resume().
ReadonlybytesThe amount of received bytes.
+ReadonlybytesThe amount of received bytes.
ReadonlybytesThe amount of bytes sent.
+ReadonlybytesThe amount of bytes sent.
ReadonlyclosedIs true after 'close' has been emitted.
ReadonlyclosedIs true after 'close' has been emitted.
ReadonlyconnectingIf true, socket.connect(options[, connectListener]) was
called and has not yet finished. It will stay true until the socket becomes
connected, then it is set to false and the 'connect' event is emitted. Note
that the socket.connect(options[, connectListener]) callback is a listener for the 'connect' event.
ReadonlydestroyedSee writable.destroyed for further details.
ReadonlyerroredReturns error if the stream has been destroyed with an error.
+ReadonlydestroyedSee writable.destroyed for further details.
ReadonlyerroredReturns error if the stream has been destroyed with an error.
Optional ReadonlylocalThe string representation of the local IP address the remote client is
connecting on. For example, in a server listening on '0.0.0.0', if a client
connects on '192.168.1.1', the value of socket.localAddress would be'192.168.1.1'.
Optional ReadonlylocalThe string representation of the local IP family. 'IPv4' or 'IPv6'.
Optional ReadonlylocalThe string representation of the local IP family. 'IPv4' or 'IPv6'.
Optional ReadonlylocalThe numeric representation of the local port. For example, 80 or 21.
Optional ReadonlylocalThe numeric representation of the local port. For example, 80 or 21.
ReadonlypendingThis is true if the socket is not connected yet, either because .connect()has not yet been called or because it is still in the process of connecting
+
ReadonlypendingThis is true if the socket is not connected yet, either because .connect()has not yet been called or because it is still in the process of connecting
(see socket.connecting).
Is true if it is safe to call read, which means
+
Is true if it is safe to call read, which means
the stream has not been destroyed or emitted 'error' or 'end'.
ReadonlyreadableReturns whether the stream was destroyed or errored before emitting 'end'.
writeOnly.ReadonlyremoteThe string representation of the remote IP address. For example,'74.125.127.100' or '2001:4860:a005::68'. Value may be undefined if
+
ReadonlyremoteThe string representation of the remote IP address. For example,'74.125.127.100' or '2001:4860:a005::68'. Value may be undefined if
the socket is destroyed (for example, if the client disconnected).
ReadonlyremoteThe string representation of the remote IP family. 'IPv4' or 'IPv6'. Value may be undefined if
+
ReadonlyremoteThe string representation of the remote IP family. 'IPv4' or 'IPv6'. Value may be undefined if
the socket is destroyed (for example, if the client disconnected).
ReadonlyremoteThe numeric representation of the remote port. For example, 80 or 21. Value may be undefined if
+
ReadonlyremoteThe numeric representation of the remote port. For example, 80 or 21. Value may be undefined if
the socket is destroyed (for example, if the client disconnected).
Optional ReadonlytimeoutThe socket timeout in milliseconds as set by socket.setTimeout().
+
Optional ReadonlytimeoutThe socket timeout in milliseconds as set by socket.setTimeout().
It is undefined if a timeout has not been set.
ReadonlywritableIs true if it is safe to call writable.write(), which means
+
ReadonlywritableIs true if it is safe to call writable.write(), which means
the stream has not been destroyed, errored, or ended.
ReadonlywritableReturns whether the stream was destroyed or errored before emitting 'finish'.
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
events.EventEmitter
+events.EventEmitter
Returns the bound address, the address family name and port of the
+
Returns the bound address, the address family name and port of the
socket as reported by the operating system:{ port: 12346, family: 'IPv4', address: '127.0.0.1' }
This method returns a new stream with chunks of the underlying stream paired with a counter +
This method returns a new stream with chunks of the underlying stream paired with a counter
in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.
Optionaloptions: Pick<Stream.ArrayOptions, "signal">a stream of indexed pairs.
v17.5.0
@@ -493,7 +493,7 @@ for the'connect' event once.
This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined
behavior.
OptionalconnectionListener: () => voidInitiate a connection on a given socket.
+OptionalconnectionListener: () => voidInitiate a connection on a given socket.
Possible signatures:
socket.connect(options[, connectListener])'connect' event once.
This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined
behavior.
OptionalconnectionListener: () => voidInitiate a connection on a given socket.
+OptionalconnectionListener: () => voidInitiate a connection on a given socket.
Possible signatures:
socket.connect(options[, connectListener])'connect' event once.
This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined
behavior.
OptionalconnectionListener: () => voidInitiate a connection on a given socket.
+OptionalconnectionListener: () => voidInitiate a connection on a given socket.
Possible signatures:
socket.connect(options[, connectListener])'connect' event once.
This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined
behavior.
OptionalconnectionListener: () => voidThe writable.cork() method forces all written data to be buffered in memory.
+
OptionalconnectionListener: () => voidThe writable.cork() method forces all written data to be buffered in memory.
The buffered data will be flushed when either the uncork or end methods are called.
The primary intent of writable.cork() is to accommodate a situation in which
several small chunks are written to the stream in rapid succession. Instead of
@@ -548,7 +548,7 @@
to be processed. However, use of writable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
stream will release any internal resources and subsequent calls to push() will be ignored.
Once destroy() has been called any further calls will be a no-op and no
further errors except from _destroy() may be emitted as 'error'.
Half-closes the socket. i.e., it sends a FIN packet. It is possible the +
Half-closes the socket. i.e., it sends a FIN packet. It is possible the -server will still send some data.
-See writable.end() for further details.
Half-closes the socket, with one final chunk of data.
Optionalcallback: () => voidOptional callback for when the socket is finished.
The socket itself.
-Half-closes the socket. i.e., it sends a FIN packet. It is possible the -server will still send some data.
-See writable.end() for further details.
Socket.end for full details.
+Half-closes the socket, with one final chunk of data.
Optionalencoding: BufferEncodingOnly used when data is string.
Optionalcallback: () => voidOptional callback for when the socket is finished.
The socket itself.
-Returns an array listing the events for which the emitter has registered +
Socket.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -691,7 +689,7 @@
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -704,10 +702,10 @@
The callback function
Pauses the reading of data. That is, 'data' events will not be emitted.
+
Pauses the reading of data. That is, 'data' events will not be emitted.
Useful to throttle back an upload.
The socket itself.
-Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
+
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -725,7 +723,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
+
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
@@ -793,7 +791,7 @@
If the socket is refed calling ref again will have no effect.
The socket itself.
Removes all listeners, or those of the specified eventName.
Removes all listeners, or those of the specified eventName.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter, so that calls can be chained.
Close the TCP connection by sending an RST packet and destroy the stream. +
Close the TCP connection by sending an RST packet and destroy the stream.
If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.
Otherwise, it will call socket.destroy with an ERR_SOCKET_CLOSED Error.
If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an ERR_INVALID_HANDLE_TYPE Error.
Resumes reading after a call to socket.pause().
Resumes reading after a call to socket.pause().
The socket itself.
-The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
Set the encoding for the socket as a Readable Stream. See readable.setEncoding() for more information.
Set the encoding for the socket as a Readable Stream. See readable.setEncoding() for more information.
Optionalencoding: BufferEncodingThe socket itself.
Enable/disable keep-alive functionality, and optionally set the initial +
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
Set initialDelay (in milliseconds) to set the delay between the last
data packet received and the first keepalive probe. Setting 0 forinitialDelay will leave the value unchanged from the default
@@ -853,7 +851,7 @@
Optionalenable: booleanOptionalinitialDelay: numberThe socket itself.
By default EventEmitters will print a warning if more than 10 listeners are
+
By default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.
OptionalnoDelay: booleanThe socket itself.
Sets the socket to timeout after timeout milliseconds of inactivity on
+
Sets the socket to timeout after timeout milliseconds of inactivity on
the socket. By default net.Socket do not have a timeout.
When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed. The user must manually call socket.end() or socket.destroy() to
end the connection.
The optional callback parameter will be added as a one-time listener for the 'timeout' event.
Optionalcallback: () => voidThe socket itself.
This method is similar to Array.prototype.some and calls fn on each chunk in the stream
+
This method is similar to Array.prototype.some and calls fn on each chunk in the stream
until the awaited return value is true (or any truthy value). Once an fn call on a chunk
awaited return value is truthy, the stream is destroyed and the promise is fulfilled with true.
If none of the fn calls on the chunks return a truthy value, the promise is fulfilled with false.
See also: writable.cork().
The readable.unpipe() method detaches a Writable stream previously attached
+
The readable.unpipe() method detaches a Writable stream previously attached
using the pipe method.
If the destination is not specified, then all pipes are detached.
If the destination is specified, but no pipe is set up for it, then
@@ -924,7 +922,7 @@
active socket in the event system. If the socket is already unrefed callingunref() again will have no effect.
The socket itself.
Passing chunk as null signals the end of the stream (EOF) and behaves the
+
Passing chunk as null signals the end of the stream (EOF) and behaves the
same as readable.push(null), after which no more data can be written. The EOF
signal is put at the end of the buffer and any buffered data will still be
flushed.
See Writable stream write() method for more
information.
Optionalcb: (err?: Error) => voidSends data on the socket. The second parameter specifies the encoding in the -case of a string. It defaults to UTF8 encoding.
-Returns true if the entire data was flushed successfully to the kernel
-buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.
The optional callback parameter will be executed when the data is finally
-written out, which may not be immediately.
See Writable stream write() method for more
-information.
Sends data on the socket, with an explicit encoding for string data.
Optionalencoding: BufferEncodingOnly used when data is string.
Optionalcb: (err?: Error) => voidStaticaddListens once to the abort event on the provided signal.
Optionalcb: (err?: Error) => voidSocket.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
@@ -1016,9 +1008,9 @@
Promise converts into readable Duplex. Value null is ignored.StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
Optionaloptions: Pick<StaticgetReturns a copy of the array of listeners for the event named eventName.
StaticgetReturns a copy of the array of listeners for the event named eventName.
For EventEmitters this behaves exactly the same as calling .listeners on
the emitter.
For EventTargets this is the only way to get the event listeners for the
@@ -1128,4 +1120,4 @@
StatictoA utility method for creating a web ReadableStream and WritableStream from a Duplex.
ReadonlyfamilyEither 'ipv4' or 'ipv6'.
ReadonlyflowlabelReadonlyportStaticparseAn input string containing an IP address and optional port, +
ReadonlyflowlabelReadonlyportStaticparseAn input string containing an IP address and optional port,
e.g. 123.1.2.3:1234 or [1::1]:1234.
Returns a SocketAddress if parsing was successful.
Otherwise returns undefined.
crypto streamsOptionalopts: DuplexOptionsIf false then the stream will automatically end the writable side when the
+
Optionalopts: DuplexOptionsIf false then the stream will automatically end the writable side when the
readable side ends. Set initially by the allowHalfOpen constructor option,
which defaults to true.
This can be changed manually to change the half-open behavior of an existing
Duplex stream instance, but must be changed before the 'end' event is emitted.
ReadonlyclosedIs true after 'close' has been emitted.
ReadonlyclosedIs true after 'close' has been emitted.
Is true after readable.destroy() has been called.
Is true if it is safe to call read, which means
the stream has not been destroyed or emitted 'error' or 'end'.
ReadonlyreadableReturns whether the stream was destroyed or errored before emitting 'end'.
ReadonlyreadableReturns whether the stream was destroyed or errored before emitting 'end'.
ReadonlyreadableReturns whether 'data' has been emitted.
ReadonlywritableIs true if it is safe to call writable.write(), which means
the stream has not been destroyed, errored, or ended.
ReadonlywritableReturns whether the stream was destroyed or errored before emitting 'finish'.
ReadonlywritableReturns whether the stream was destroyed or errored before emitting 'finish'.
ReadonlywritableNumber of times writable.uncork() needs to be
called in order to fully uncork the stream.
Optional[captureEvent emitter +
Optional[captureEvent emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
This method returns a new stream with chunks of the underlying stream paired with a counter +
This method returns a new stream with chunks of the underlying stream paired with a counter
in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.
Optionaloptions: Pick<Stream.ArrayOptions, "signal">a stream of indexed pairs.
v17.5.0
@@ -388,7 +388,7 @@ to be processed. However, use ofwritable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
stream will release any internal resources and subsequent calls to push() will be ignored.
Once destroy() has been called any further calls will be a no-op and no
further errors except from _destroy() may be emitted as 'error'.
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
This method is similar to Array.prototype.every and calls fn on each chunk in the stream
+
This method is similar to Array.prototype.every and calls fn on each chunk in the stream
to check if all awaited return values are truthy value for fn. Once an fn call on a chunk
awaited return value is falsy, the stream is destroyed and the promise is fulfilled with false.
If all of the fn calls on the chunks return a truthy value, the promise is fulfilled with true.
Returns the current max listener value for the EventEmitter which is either
set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.
The readable.isPaused() method returns the current operating state of the Readable.
+
The readable.isPaused() method returns the current operating state of the Readable.
This is used primarily by the mechanism that underlies the readable.pipe() method.
In most typical cases, there will be no reason to use this method directly.
const readable = new stream.Readable();
readable.isPaused(); // === false
readable.pause();
readable.isPaused(); // === true
readable.resume();
readable.isPaused(); // === false
The iterator created by this method gives users the option to cancel the destruction +
The iterator created by this method gives users the option to cancel the destruction
of the stream if the for await...of loop is exited by return, break, or throw,
or if the iterator should destroy the stream if the stream emitted an error during iteration.
Optionaloptions: { destroyOnReturn?: boolean }OptionaldestroyOnReturn?: booleanWhen set to false, calling return on the async iterator,
@@ -514,19 +505,19 @@
The name of the event being listened for
Optionallistener: FunctionThe event handler function
Returns a copy of the array of listeners for the event named eventName.
Returns a copy of the array of listeners for the event named eventName.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
This method allows mapping over the stream. The fn function will be called for every chunk in the stream. +
This method allows mapping over the stream. The fn function will be called for every chunk in the stream.
If the fn function returns a promise - that promise will be awaited before being passed to the result stream.
a function to map over every chunk in the stream. Async or not.
Optionaloptions: Stream.ArrayOptionsa stream mapped with the function fn.
Adds the listener function to the end of the listeners array for the event
+
Adds the listener function to the end of the listeners array for the event
named eventName. No checks are made to see if the listener has already
been added. Multiple calls passing the same combination of eventName and
listener will result in the listener being added, and called, multiple times.
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -554,7 +545,7 @@
The callback function
The readable.pause() method will cause a stream in flowing mode to stop
+
The readable.pause() method will cause a stream in flowing mode to stop
emitting 'data' events, switching out of flowing mode. Any data that
becomes available will remain in the internal buffer.
const readable = getReadableStreamSomehow();
readable.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
readable.pause();
console.log('There will be no additional data for 1 second.');
setTimeout(() => {
console.log('Now data will start flowing again.');
readable.resume();
}, 1000);
});
@@ -562,7 +553,7 @@
The readable.pause() method has no effect if there is a 'readable' event listener.
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
+
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -580,13 +571,13 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
+
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
The readable.read() method reads data out of the internal buffer and
+
The readable.read() method reads data out of the internal buffer and
returns it. If no data is available to be read, null is returned. By default,
the data is returned as a Buffer object unless an encoding has been
specified using the readable.setEncoding() method or the stream is operating
@@ -624,7 +615,7 @@
been emitted will return null. No runtime error will be raised.
Optionalsize: numberOptional argument to specify how much data to read.
This method calls fn on each chunk of the stream in order, passing it the result from the calculation +
This method calls fn on each chunk of the stream in order, passing it the result from the calculation on the previous element. It returns a promise for the final value of the reduction.
If no initial value is supplied the first chunk of the stream is used as the initial value.
If the stream is empty, the promise is rejected with a TypeError with the ERR_INVALID_ARGS code property.
Returns a reference to the EventEmitter, so that calls can be chained.
OptionaleventName: string | symbolRemoves the specified listener from the listener array for the event named eventName.
Removes the specified listener from the listener array for the event named eventName.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
@@ -677,7 +668,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The readable.resume() method causes an explicitly paused Readable stream to
+
The readable.resume() method causes an explicitly paused Readable stream to
resume emitting 'data' events, switching the stream into flowing mode.
The readable.resume() method can be used to fully consume the data from a
stream without actually processing any of that data:
The readable.resume() method has no effect if there is a 'readable' event listener.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
The readable.setEncoding() method sets the character encoding for
+
The readable.setEncoding() method sets the character encoding for
data read from the Readable stream.
By default, no encoding is assigned and stream data will be returned as Buffer objects. Setting an encoding causes the stream data
to be returned as strings of the specified encoding rather than as Buffer objects. For instance, calling readable.setEncoding('utf8') will cause the
@@ -703,13 +694,13 @@
The encoding to use.
By default EventEmitters will print a warning if more than 10 listeners are
+
By default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter, so that calls can be chained.
This method is similar to Array.prototype.some and calls fn on each chunk in the stream
+
This method is similar to Array.prototype.some and calls fn on each chunk in the stream
until the awaited return value is true (or any truthy value). Once an fn call on a chunk
awaited return value is truthy, the stream is destroyed and the promise is fulfilled with true.
If none of the fn calls on the chunks return a truthy value, the promise is fulfilled with false.
See also: writable.cork().
The readable.unpipe() method detaches a Writable stream previously attached
+
The readable.unpipe() method detaches a Writable stream previously attached
using the pipe method.
If the destination is not specified, then all pipes are detached.
If the destination is specified, but no pipe is set up for it, then
@@ -750,7 +741,7 @@
Optionaldestination: WritableStreamOptional specific stream to unpipe
Passing chunk as null signals the end of the stream (EOF) and behaves the
+
Passing chunk as null signals the end of the stream (EOF) and behaves the
same as readable.push(null), after which no more data can be written. The EOF
signal is put at the end of the buffer and any buffered data will still be
flushed.
null. For object mode streams, chunk may be any JavaScript value.
Optionalencoding: BufferEncodingEncoding of string chunks. Must be a valid Buffer encoding, such as 'utf8' or 'ascii'.
Prior to Node.js 0.10, streams did not implement the entire node:stream module API as it is currently defined. (See Compatibility for more
+
Prior to Node.js 0.10, streams did not implement the entire node:stream module API as it is currently defined. (See Compatibility for more
information.)
When using an older Node.js library that emits 'data' events and has a pause method that is advisory only, the readable.wrap() method can be used to create a Readable
stream that uses
@@ -789,7 +780,7 @@
An "old style" readable stream
The writable.write() method writes some data to the stream, and calls the
+
The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
@@ -825,44 +816,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
@@ -896,9 +858,9 @@
Promise converts into readable Duplex. Value null is ignored.StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
Optionaloptions: Pick<StaticgetReturns a copy of the array of listeners for the event named eventName.
StaticgetReturns a copy of the array of listeners for the event named eventName.
For EventEmitters this behaves exactly the same as calling .listeners on
the emitter.
For EventTargets this is the only way to get the event listeners for the
@@ -1008,4 +970,4 @@
StatictoA utility method for creating a web ReadableStream and WritableStream from a Duplex.
The stream.PassThrough class is a trivial implementation of a Transform stream that simply passes the input bytes across to the output. Its purpose is
primarily for examples and testing, but there are some use cases where stream.PassThrough is useful as a building block for novel sorts of streams.
Optionalopts: TransformOptionsOptionalopts: TransformOptionsIf false then the stream will automatically end the writable side when the
readable side ends. Set initially by the allowHalfOpen constructor option,
which defaults to true.
This can be changed manually to change the half-open behavior of an existing
Duplex stream instance, but must be changed before the 'end' event is emitted.
ReadonlyclosedIs true after 'close' has been emitted.
ReadonlyclosedIs true after 'close' has been emitted.
Is true after readable.destroy() has been called.
v8.0.0
@@ -185,7 +185,7 @@Installing a listener using this symbol does not change the behavior once an 'error' event is emitted. Therefore, the process will still crash if no
regular 'error' listener is installed.
Optional_Optional_Calls readable.destroy() with an AbortError and returns
+
Optional_Optional_AsyncIterator to fully consume the stream.
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
This method returns a new stream with chunks of the underlying stream paired with a counter +
This method returns a new stream with chunks of the underlying stream paired with a counter
in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.
Optionaloptions: Pick<Stream.ArrayOptions, "signal">a stream of indexed pairs.
v17.5.0
@@ -384,7 +384,7 @@ to be processed. However, use ofwritable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
stream will release any internal resources and subsequent calls to push() will be ignored.
Once destroy() has been called any further calls will be a no-op and no
further errors except from _destroy() may be emitted as 'error'.
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -537,7 +528,7 @@
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -550,7 +541,7 @@
The callback function
The readable.pause() method will cause a stream in flowing mode to stop
+
The readable.pause() method will cause a stream in flowing mode to stop
emitting 'data' events, switching out of flowing mode. Any data that
becomes available will remain in the internal buffer.
const readable = getReadableStreamSomehow();
readable.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
readable.pause();
console.log('There will be no additional data for 1 second.');
setTimeout(() => {
console.log('Now data will start flowing again.');
readable.resume();
}, 1000);
});
@@ -568,7 +559,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -576,7 +567,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
+
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
@@ -673,7 +664,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The readable.resume() method causes an explicitly paused Readable stream to
+
The readable.resume() method causes an explicitly paused Readable stream to
resume emitting 'data' events, switching the stream into flowing mode.
The readable.resume() method can be used to fully consume the data from a
stream without actually processing any of that data:
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
The readable.setEncoding() method sets the character encoding for
+
The readable.setEncoding() method sets the character encoding for
data read from the Readable stream.
By default, no encoding is assigned and stream data will be returned as Buffer objects. Setting an encoding causes the stream data
to be returned as strings of the specified encoding rather than as Buffer objects. For instance, calling readable.setEncoding('utf8') will cause the
@@ -736,7 +727,7 @@
See also: writable.cork().
The readable.unpipe() method detaches a Writable stream previously attached
+
The readable.unpipe() method detaches a Writable stream previously attached
using the pipe method.
If the destination is not specified, then all pipes are detached.
If the destination is specified, but no pipe is set up for it, then
@@ -821,44 +812,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
@@ -892,9 +854,9 @@
Promise converts into readable Duplex. Value null is ignored.StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
Optionaloptions: Pick<StaticgetReturns a copy of the array of listeners for the event named eventName.
StaticgetReturns a copy of the array of listeners for the event named eventName.
For EventEmitters this behaves exactly the same as calling .listeners on
the emitter.
For EventTargets this is the only way to get the event listeners for the
@@ -1004,4 +966,4 @@
StatictoA utility method for creating a web ReadableStream and WritableStream from a Duplex.
crypto streamsOptionalopts: TransformOptionsIf false then the stream will automatically end the writable side when the
+
Optionalopts: TransformOptionsIf false then the stream will automatically end the writable side when the
readable side ends. Set initially by the allowHalfOpen constructor option,
which defaults to true.
This can be changed manually to change the half-open behavior of an existing
Duplex stream instance, but must be changed before the 'end' event is emitted.
ReadonlyclosedIs true after 'close' has been emitted.
ReadonlyclosedIs true after 'close' has been emitted.
Is true after readable.destroy() has been called.
v8.0.0
@@ -192,7 +192,7 @@Installing a listener using this symbol does not change the behavior once an 'error' event is emitted. Therefore, the process will still crash if no
regular 'error' listener is installed.
Optional_Optional_Calls readable.destroy() with an AbortError and returns
+
Optional_Optional_AsyncIterator to fully consume the stream.
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
This method returns a new stream with chunks of the underlying stream paired with a counter +
This method returns a new stream with chunks of the underlying stream paired with a counter
in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.
Optionaloptions: Pick<Stream.ArrayOptions, "signal">a stream of indexed pairs.
v17.5.0
@@ -391,7 +391,7 @@ to be processed. However, use ofwritable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable
stream will release any internal resources and subsequent calls to push() will be ignored.
Once destroy() has been called any further calls will be a no-op and no
further errors except from _destroy() may be emitted as 'error'.
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -544,7 +535,7 @@
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -557,7 +548,7 @@
The callback function
The readable.pause() method will cause a stream in flowing mode to stop
+
The readable.pause() method will cause a stream in flowing mode to stop
emitting 'data' events, switching out of flowing mode. Any data that
becomes available will remain in the internal buffer.
const readable = getReadableStreamSomehow();
readable.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
readable.pause();
console.log('There will be no additional data for 1 second.');
setTimeout(() => {
console.log('Now data will start flowing again.');
readable.resume();
}, 1000);
});
@@ -575,7 +566,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -583,7 +574,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
+
Optionalencoding: BufferEncodingReturns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
@@ -680,7 +671,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The readable.resume() method causes an explicitly paused Readable stream to
+
The readable.resume() method causes an explicitly paused Readable stream to
resume emitting 'data' events, switching the stream into flowing mode.
The readable.resume() method can be used to fully consume the data from a
stream without actually processing any of that data:
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
The readable.setEncoding() method sets the character encoding for
+
The readable.setEncoding() method sets the character encoding for
data read from the Readable stream.
By default, no encoding is assigned and stream data will be returned as Buffer objects. Setting an encoding causes the stream data
to be returned as strings of the specified encoding rather than as Buffer objects. For instance, calling readable.setEncoding('utf8') will cause the
@@ -743,7 +734,7 @@
See also: writable.cork().
The readable.unpipe() method detaches a Writable stream previously attached
+
The readable.unpipe() method detaches a Writable stream previously attached
using the pipe method.
If the destination is not specified, then all pipes are detached.
If the destination is specified, but no pipe is set up for it, then
@@ -828,44 +819,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
@@ -899,9 +861,9 @@
Promise converts into readable Duplex. Value null is ignored.StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
StaticfromA utility method for creating a Duplex from a web ReadableStream and WritableStream.
Optionaloptions: Pick<StaticgetReturns a copy of the array of listeners for the event named eventName.
StaticgetReturns a copy of the array of listeners for the event named eventName.
For EventEmitters this behaves exactly the same as calling .listeners on
the emitter.
For EventTargets this is the only way to get the event listeners for the
@@ -1011,4 +973,4 @@
StatictoA utility method for creating a web ReadableStream and WritableStream from a Duplex.
Optional_Optional_Optional[captureEvent emitter +
Optional[captureEvent emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter +
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Event emitter The defined events on documents including:
Optionaloptions: { signal: AbortSignal }The writable.cork() method forces all written data to be buffered in memory.
+
Optionaloptions: { signal: AbortSignal }The writable.cork() method forces all written data to be buffered in memory.
The buffered data will be flushed when either the uncork or end methods are called.
The primary intent of writable.cork() is to accommodate a situation in which
several small chunks are written to the stream in rapid succession. Instead of
@@ -202,7 +202,7 @@
to be processed. However, use of writable.cork() without implementing writable._writev() may have an adverse effect on throughput.
See also: writable.uncork(), writable._writev().
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
+
Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
stream has ended and subsequent calls to write() or end() will result in
an ERR_STREAM_DESTROYED error.
This is a destructive and immediate way to destroy a stream. Previous calls to write() may not have drained, and may trigger an ERR_STREAM_DESTROYED error.
@@ -214,23 +214,14 @@
but instead implement writable._destroy().
Optionalerror: ErrorOptional, an error to emit with 'error' event.
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
+
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Calling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
-Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
+
Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
+Optionalcb: () => voidCallback for when the stream is finished.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalcb: () => voidCalling the writable.end() method signals that no more data will be written
-to the Writable. The optional chunk and encoding arguments allow one
-final additional chunk of data to be written immediately before closing the
-stream.
Calling the write method after calling end will raise an error.
-// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
-
-
+Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Signals that no more data will be written, with one final chunk of data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding if chunk is a string
Optionalcb: () => voidReturns an array listing the events for which the emitter has registered +
Optionalcb: () => voidCallback for when the stream is finished.
+Writable.end for full details.
+Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
@@ -290,7 +281,7 @@
The callback function
Adds a one-time listener function for the event named eventName. The
+
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -303,7 +294,7 @@
The callback function
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
+
Optionaloptions: { end?: boolean }Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
+
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
@@ -321,7 +312,7 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The callback function
Returns a copy of the array of listeners for the event named eventName,
+
Returns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
@@ -360,10 +351,10 @@
Returns a reference to the EventEmitter, so that calls can be chained.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.
The new default encoding
By default EventEmitters will print a warning if more than 10 listeners are
+
By default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.
See also: writable.cork().
The writable.write() method writes some data to the stream, and calls the
+
The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
@@ -420,44 +411,15 @@
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
The writable.write() method writes some data to the stream, and calls the
-supplied callback once the data has been fully handled. If an error
-occurs, the callback will be called with the error as its
-first argument. The callback is called asynchronously and before 'error' is
-emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
-If false is returned, further attempts to write data to the stream should
-stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
-return false. Once all currently buffered chunks are drained (accepted for
-delivery by the operating system), the 'drain' event will be emitted.
-Once write() returns false, do not write more chunks
-until the 'drain' event is emitted. While calling write() on a stream that
-is not draining is allowed, Node.js will buffer all written chunks until
-maximum memory usage occurs, at which point it will abort unconditionally.
-Even before it aborts, high memory usage will cause poor garbage collector
-performance and high RSS (which is not typically released back to the system,
-even after the memory is no longer required). Since TCP sockets may never
-drain if the remote peer does not read the data, writing a socket that is
-not draining may lead to a remotely exploitable vulnerability.
Writing data while the stream is not draining is particularly
-problematic for a Transform, because the Transform streams are paused
-by default until they are piped or a 'data' or 'readable' event handler
-is added.
If the data to be written can be generated or fetched on demand, it is
-recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
-possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});
-
-
-A Writable stream in object mode will always ignore the encoding argument.
Writes data to the stream, with an explicit encoding for string data.
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
The encoding, if chunk is a string.
Optionalcallback: (error: Error) => voidCallback for when this chunk of data is flushed.
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
StaticaddListens once to the abort event on the provided signal.
Writable.write for full details.
+StaticaddListens once to the abort event on the provided signal.
Listening to the abort event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation(). Unfortunately Node.js cannot change
diff --git a/docs/classes/_internal_.Stream.html b/docs/classes/_internal_.Stream.html
index a2246249..984e86d0 100644
--- a/docs/classes/_internal_.Stream.html
+++ b/docs/classes/_internal_.Stream.html
@@ -6,7 +6,7 @@
added and 'removeListener' when existing listeners are removed.
It supports the following option:
delete keyword on any properties of URL objects (e.g. delete myURL.protocol, delete myURL.pathname, etc) has no effect but will still
return true.
A signal representing possible cancellation
A stream to attach a signal to.
Optionaloptions: DuplexOptionsA value to pass to both Duplex constructors, to set options such as buffering.
Optionaloptions: Stream.FinishedOptionsOptionaloptions: Stream.FinishedOptionsA readable and/or writable stream/webstream.
+A readable and/or writable stream/webstream.
A function to get notified when a stream is no longer readable, writable or has experienced an error or a premature close event.
import { finished } from 'node:stream';
import fs from 'node:fs';
const rs = fs.createReadStream('archive.tar');
finished(rs, (err) => {
if (err) {
console.error('Stream failed.', err);
} else {
console.log('Stream is done reading.');
}
});
rs.resume(); // Drain the stream.
@@ -15,11 +15,11 @@
const cleanup = finished(rs, (err) => {
cleanup();
// ...
});
-A readable and/or writable stream.
+A readable and/or writable stream.
A callback function that takes an optional error argument.
A cleanup function which removes all registered listeners.
A readable and/or writable stream/webstream.
+A readable and/or writable stream/webstream.
A function to get notified when a stream is no longer readable, writable or has experienced an error or a premature close event.
import { finished } from 'node:stream';
import fs from 'node:fs';
const rs = fs.createReadStream('archive.tar');
finished(rs, (err) => {
if (err) {
console.error('Stream failed.', err);
} else {
console.log('Stream is done reading.');
}
});
rs.resume(); // Drain the stream.
@@ -36,8 +36,8 @@
const cleanup = finished(rs, (err) => {
cleanup();
// ...
});
-A readable and/or writable stream.
+A readable and/or writable stream.
A callback function that takes an optional error argument.
A cleanup function which removes all registered listeners.
Returns whether the stream has encountered an error.
Returns whether the stream is readable.
Only returns null if stream is not a valid Readable, Duplex or ReadableStream.
Returns whether the stream is writable.
Only returns null if stream is not a valid Writable, Duplex or WritableStream.
Optionaloptions: FinishedOptionsOptionaloptions: FinishedOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsOptionaloptions: PipelineOptionsCalled when the pipeline is fully done.
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -48,7 +48,7 @@
Called when the pipeline is fully done.
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -73,7 +73,7 @@
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -98,7 +98,7 @@
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -123,7 +123,7 @@
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -146,9 +146,9 @@
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!!!');
}
});
});
-Called when the pipeline is fully done.
+Called when the pipeline is fully done.
A module method to pipe between streams and generators forwarding errors and +
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.');
}
},
);
@@ -171,5 +171,5 @@
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!!!');
}
});
});
-Describes a user-defined AsyncIterator that is also async iterable.
-OptionalreturnOptionalvalue: TReturn | PromiseLike<TReturn>OptionalthrowOptionale: anyOptionalrequireDisables automatic emitDestroy when the object is garbage collected.
This usually does not need to be set (even if emitDestroy is called
diff --git a/docs/interfaces/_internal_.AwsCredentialIdentity.html b/docs/interfaces/_internal_.AwsCredentialIdentity.html
index 92db6873..5a10e580 100644
--- a/docs/interfaces/_internal_.AwsCredentialIdentity.html
+++ b/docs/interfaces/_internal_.AwsCredentialIdentity.html
@@ -1,4 +1,4 @@
-
InternalInternalOptionalsigv4aThis option will override the AWS sigv4a signing regionSet from any other source.
The lookup order is:
diff --git a/docs/interfaces/_internal_.AwsSdkSigV4AuthInputConfig.html b/docs/interfaces/_internal_.AwsSdkSigV4AuthInputConfig.html index 5a9f9bb5..9eefc61d 100644 --- a/docs/interfaces/_internal_.AwsSdkSigV4AuthInputConfig.html +++ b/docs/interfaces/_internal_.AwsSdkSigV4AuthInputConfig.html @@ -1,4 +1,4 @@ -
Since
v0.4.5
-