Skip to main content
Skip to main content

internal

admin/discounts.internal.internal

Namespaces

Classes

Interfaces

References

Duplex

Re-exports Duplex


DuplexOptions

Re-exports DuplexOptions


PassThrough

Re-exports PassThrough


Readable

Re-exports Readable


Stream

Re-exports Stream


Transform

Re-exports Transform


TransformCallback

Re-exports TransformCallback


TransformOptions

Re-exports TransformOptions

Type Aliases

PipelineCallback

PipelineCallback<S>: S extends PipelineDestinationPromiseFunction<any, infer P> ? (err: ErrnoException | null, value: P) => void : (err: ErrnoException | null) => void

Type parameters

SPipelineDestination<any, any>Required

PipelineDestination

PipelineDestination<S, P>: S extends PipelineTransformSource<infer ST> ? WritableStream | PipelineDestinationIterableFunction<ST> | PipelineDestinationPromiseFunction<ST, P> : never

Type parameters

PobjectRequired

PipelineDestinationIterableFunction

PipelineDestinationIterableFunction<T>: (source: AsyncIterable<T>) => AsyncIterable<any>

Type parameters

TobjectRequired

Type declaration

(source): AsyncIterable<any>

Parameters
sourceAsyncIterable<T>Required
Returns

AsyncIterable<any>

AsyncIterableAsyncIterable<any>Required

PipelineDestinationPromiseFunction

PipelineDestinationPromiseFunction<T, P>: (source: AsyncIterable<T>) => Promise<P>

Type parameters

TobjectRequired
PobjectRequired

Type declaration

(source): Promise<P>

Parameters
sourceAsyncIterable<T>Required
Returns

Promise<P>

PromisePromise<P>Required

PipelinePromise

PipelinePromise<S>: S extends PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>

Type parameters

SPipelineDestination<any, any>Required

PipelineSource

PipelineSource<T>: Iterable<T> | AsyncIterable<T> | ReadableStream | PipelineSourceFunction<T>

Type parameters

TobjectRequired

PipelineSourceFunction

PipelineSourceFunction<T>: () => Iterable<T> | AsyncIterable<T>

Type parameters

TobjectRequired

Type declaration

(): Iterable<T> | AsyncIterable<T>

Returns

Iterable<T> | AsyncIterable<T>

Iterable<T\> \| AsyncIterable<T\>Iterable<T> | AsyncIterable<T>

PipelineTransform

PipelineTransform<S, U>: ReadWriteStream | (source: S extends (...args: any[]) => Iterable<infer ST> | AsyncIterable<infer ST> ? AsyncIterable<ST> : S) => AsyncIterable<U>

Type parameters

UobjectRequired

PipelineTransformSource

PipelineTransformSource<T>: PipelineSource<T> | PipelineTransform<any, T>

Type parameters

TobjectRequired

Variables

consumers

Const consumers: typeof internal


promises

Const promises: typeof internal

Functions

addAbortSignal

addAbortSignal<T>(signal, stream): T

A stream to attach a signal to.

Attaches an AbortSignal to a readable or writeable stream. This lets code control stream destruction using an AbortController.

Calling abort on the AbortController corresponding to the passedAbortSignal will behave the same way as calling .destroy(new AbortError())on the stream, and controller.error(new AbortError()) for webstreams.

const fs = require('node:fs');

const controller = new AbortController();
const read = addAbortSignal(
controller.signal,
fs.createReadStream(('object.json')),
);
// Later, abort the operation closing the stream
controller.abort();

Or using an AbortSignal with a readable stream as an async iterable:

const controller = new AbortController();
setTimeout(() => controller.abort(), 10_000); // set a timeout
const stream = addAbortSignal(
controller.signal,
fs.createReadStream(('object.json')),
);
(async () => {
try {
for await (const chunk of stream) {
await process(chunk);
}
} catch (e) {
if (e.name === 'AbortError') {
// The operation was cancelled
} else {
throw e;
}
}
})();

Or using an AbortSignal with a ReadableStream:

const controller = new AbortController();
const rs = new ReadableStream({
start(controller) {
controller.enqueue('hello');
controller.enqueue('world');
controller.close();
},
});

addAbortSignal(controller.signal, rs);

finished(rs, (err) => {
if (err) {
if (err.name === 'AbortError') {
// The operation was cancelled
}
}
});

const reader = rs.getReader();

reader.read().then(({ value, done }) => {
console.log(value); // hello
console.log(done); // false
controller.abort();
});
TStreamRequired

Parameters

signalAbortSignalRequired
A signal representing possible cancellation
streamTRequired
a stream to attach a signal to

Returns

T

Since

v15.4.0


finished

finished(stream, options, callback): () => void

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.

const { finished } = require('node:stream');
const fs = require('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.

Especially useful in error handling scenarios where a stream is destroyed prematurely (like an aborted HTTP request), and will not emit 'end'or 'finish'.

The finished API provides promise version.

stream.finished() leaves dangling event listeners (in particular'error', 'end', 'finish' and 'close') after callback has been invoked. The reason for this is so that unexpected 'error' events (due to incorrect stream implementations) do not cause unexpected crashes. If this is unwanted behavior then the returned cleanup function needs to be invoked in the callback:

const cleanup = finished(rs, (err) => {
cleanup();
// ...
});

Parameters

A readable and/or writable stream.
optionsFinishedOptionsRequired
callback(err?: null | ErrnoException) => voidRequired
A callback function that takes an optional error argument.

Returns

fn

() => `void`() => void
A cleanup function which removes all registered listeners.

(): void

Returns

void

voidvoid

Since

v10.0.0

finished(stream, callback): () => void

Parameters

callback(err?: null | ErrnoException) => voidRequired

Returns

fn

() => `void`() => void

(): void

Returns

void

voidvoid

getDefaultHighWaterMark

getDefaultHighWaterMark(objectMode): number

Returns the default highWaterMark used by streams. Defaults to 16384 (16 KiB), or 16 for objectMode.

Parameters

objectModebooleanRequired

Returns

number

numbernumber

Since

v19.9.0


isErrored

isErrored(stream): boolean

Returns whether the stream has encountered an error.

Parameters

Returns

boolean

booleanboolean

Since

v17.3.0, v16.14.0


isReadable

isReadable(stream): boolean

Returns whether the stream is readable.

Parameters

streamReadableStream | ReadableRequired

Returns

boolean

booleanboolean

Since

v17.4.0, v16.14.0


pipeline

pipeline<A, B>(source, destination, callback?): B extends WritableStream ? B : WritableStream

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

const { pipeline } = require('node:stream');
const fs = require('node:fs');
const zlib = require('node:zlib');

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

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

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

The pipeline API provides a promise version.

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

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

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

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

const fs = require('node:fs');
const http = require('node:http');
const { pipeline } = require('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!!!');
}
});
});

Parameters

sourceARequired
destinationBRequired
callbackPipelineCallback<B>
Called when the pipeline is fully done.

Returns

B extends WritableStream ? B : WritableStream

`B` extends [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream) ? `B` : [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream)B extends WritableStream ? B : WritableStream

Since

v10.0.0

pipeline<A, T1, B>(source, transform1, destination, callback?): B extends WritableStream ? B : WritableStream

Parameters

sourceARequired
transform1T1Required
destinationBRequired
callbackPipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

`B` extends [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream) ? `B` : [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream)B extends WritableStream ? B : WritableStream

pipeline<A, T1, T2, B>(source, transform1, transform2, destination, callback?): B extends WritableStream ? B : WritableStream

Parameters

sourceARequired
transform1T1Required
transform2T2Required
destinationBRequired
callbackPipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

`B` extends [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream) ? `B` : [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream)B extends WritableStream ? B : WritableStream

pipeline<A, T1, T2, T3, B>(source, transform1, transform2, transform3, destination, callback?): B extends WritableStream ? B : WritableStream

Parameters

sourceARequired
transform1T1Required
transform2T2Required
transform3T3Required
destinationBRequired
callbackPipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

`B` extends [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream) ? `B` : [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream)B extends WritableStream ? B : WritableStream

pipeline<A, T1, T2, T3, T4, B>(source, transform1, transform2, transform3, transform4, destination, callback?): B extends WritableStream ? B : WritableStream

Parameters

sourceARequired
transform1T1Required
transform2T2Required
transform3T3Required
transform4T4Required
destinationBRequired
callbackPipelineCallback<B>

Returns

B extends WritableStream ? B : WritableStream

`B` extends [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream) ? `B` : [`WritableStream`](/references/js-client/internal/interfaces/admin_discounts.internal.WritableStream)B extends WritableStream ? B : WritableStream

pipeline(streams, callback?): WritableStream

Parameters

streamsreadonly (ReadableStream | WritableStream | ReadWriteStream)[]Required
callback(err: null | ErrnoException) => void

Returns

WritableStream

writablebooleanRequired
addListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
emit(eventName: string | symbol, ...args: any[]) => booleanRequired
end(cb?: () => void) => WritableStream(data: string | Uint8Array, cb?: () => void) => WritableStream(str: string, encoding?: BufferEncoding, cb?: () => void) => WritableStreamRequired
eventNames() => (string | symbol)[]Required
getMaxListeners() => numberRequired
listenerCount(eventName: string | symbol, listener?: Function) => numberRequired
listeners(eventName: string | symbol) => Function[]Required
off(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
on(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
once(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
prependListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
rawListeners(eventName: string | symbol) => Function[]Required
removeAllListeners(event?: string | symbol) => WritableStreamRequired
removeListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
setMaxListeners(n: number) => WritableStreamRequired
write(buffer: string | Uint8Array, cb?: (err?: null | Error) => void) => boolean(str: string, encoding?: BufferEncoding, cb?: (err?: null | Error) => void) => booleanRequired

pipeline(stream1, stream2, ...streams): WritableStream

Parameters

stream1ReadableStreamRequired
streams(WritableStream | ReadWriteStream | (err: null | ErrnoException) => void)[]Required

Returns

WritableStream

writablebooleanRequired
addListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
emit(eventName: string | symbol, ...args: any[]) => booleanRequired
end(cb?: () => void) => WritableStream(data: string | Uint8Array, cb?: () => void) => WritableStream(str: string, encoding?: BufferEncoding, cb?: () => void) => WritableStreamRequired
eventNames() => (string | symbol)[]Required
getMaxListeners() => numberRequired
listenerCount(eventName: string | symbol, listener?: Function) => numberRequired
listeners(eventName: string | symbol) => Function[]Required
off(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
on(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
once(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
prependListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
rawListeners(eventName: string | symbol) => Function[]Required
removeAllListeners(event?: string | symbol) => WritableStreamRequired
removeListener(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequired
setMaxListeners(n: number) => WritableStreamRequired
write(buffer: string | Uint8Array, cb?: (err?: null | Error) => void) => boolean(str: string, encoding?: BufferEncoding, cb?: (err?: null | Error) => void) => booleanRequired

setDefaultHighWaterMark

setDefaultHighWaterMark(objectMode, value): void

Sets the default highWaterMark used by streams.

Parameters

objectModebooleanRequired
valuenumberRequired
highWaterMark value

Returns

void

voidvoid

Since

v19.9.0

Was this section helpful?