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
PipelineDestination
PipelineDestination<S
, P
>: S
extends PipelineTransformSource
<infer ST> ? WritableStream
| PipelineDestinationIterableFunction
<ST
> | PipelineDestinationPromiseFunction
<ST
, P
> : never
Type parameters
P
objectRequiredPipelineDestinationIterableFunction
PipelineDestinationIterableFunction<T
>: (source
: AsyncIterable
<T
>) => AsyncIterable
<any
>
Type parameters
T
objectRequiredType declaration
(source
): AsyncIterable
<any
>
Parameters
Returns
AsyncIterable
<any
>
PipelineDestinationPromiseFunction
PipelineDestinationPromiseFunction<T
, P
>: (source
: AsyncIterable
<T
>) => Promise
<P
>
Type parameters
T
objectRequiredP
objectRequiredType declaration
(source
): Promise
<P
>
Parameters
Returns
Promise
<P
>
Promise
Promise<P>RequiredPipelinePromise
PipelinePromise<S
>: S
extends PipelineDestinationPromiseFunction
<any
, infer P> ? Promise
<P
> : Promise
<void
>
Type parameters
PipelineSource
PipelineSource<T
>: Iterable
<T
> | AsyncIterable
<T
> | ReadableStream
| PipelineSourceFunction
<T
>
Type parameters
T
objectRequiredPipelineSourceFunction
PipelineSourceFunction<T
>: () => Iterable
<T
> | AsyncIterable
<T
>
Type parameters
T
objectRequiredType 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
U
objectRequiredPipelineTransformSource
PipelineTransformSource<T
>: PipelineSource
<T
> | PipelineTransform
<any
, T
>
Type parameters
T
objectRequiredVariables
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.
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();
});
Parameters
signal
AbortSignalRequiredstream
TRequiredReturns
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.
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:
Parameters
Returns
fn
() => `void`
() => void(): void
Returns
void
void
voidSince
v10.0.0
finished(stream
, callback
): () => void
Parameters
Returns
fn
() => `void`
() => void(): void
Returns
void
void
voidgetDefaultHighWaterMark
getDefaultHighWaterMark(objectMode
): number
Returns the default highWaterMark used by streams.
Defaults to 16384
(16 KiB), or 16
for objectMode
.
Parameters
objectMode
booleanRequiredReturns
number
number
numberSince
v19.9.0
isErrored
isErrored(stream
): boolean
Returns whether the stream has encountered an error.
Parameters
Returns
boolean
boolean
booleanSince
v17.3.0, v16.14.0
isReadable
isReadable(stream
): boolean
Returns whether the stream is readable.
Parameters
Returns
boolean
boolean
booleanSince
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!!!');
}
});
});
B
WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>RequiredParameters
source
ARequireddestination
BRequiredcallback
PipelineCallback<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 : WritableStreamSince
v10.0.0
pipeline<A
, T1
, B
>(source
, transform1
, destination
, callback?
): B
extends WritableStream
? B
: WritableStream
B
WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>RequiredParameters
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 : WritableStreampipeline<A
, T1
, T2
, B
>(source
, transform1
, transform2
, destination
, callback?
): B
extends WritableStream
? B
: WritableStream
B
WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>RequiredParameters
source
ARequiredtransform1
T1Requiredtransform2
T2Requireddestination
BRequiredcallback
PipelineCallback<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 : WritableStreampipeline<A
, T1
, T2
, T3
, B
>(source
, transform1
, transform2
, transform3
, destination
, callback?
): B
extends WritableStream
? B
: WritableStream
B
WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>RequiredParameters
source
ARequiredtransform1
T1Requiredtransform2
T2Requiredtransform3
T3Requireddestination
BRequiredcallback
PipelineCallback<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 : WritableStreampipeline<A
, T1
, T2
, T3
, T4
, B
>(source
, transform1
, transform2
, transform3
, transform4
, destination
, callback?
): B
extends WritableStream
? B
: WritableStream
B
WritableStream | PipelineDestinationIterableFunction<string | Buffer> | PipelineDestinationPromiseFunction<string | Buffer, any> | PipelineDestinationIterableFunction<any> | PipelineDestinationPromiseFunction<any, any>RequiredParameters
source
ARequiredtransform1
T1Requiredtransform2
T2Requiredtransform3
T3Requiredtransform4
T4Requireddestination
BRequiredcallback
PipelineCallback<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 : WritableStreampipeline(streams
, callback?
): WritableStream
Parameters
callback
(err: null | ErrnoException) => voidReturns
writable
booleanRequiredaddListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredemit
(eventName: string | symbol, ...args: any[]) => booleanRequiredend
(cb?: () => void) => WritableStream(data: string | Uint8Array, cb?: () => void) => WritableStream(str: string, encoding?: BufferEncoding, cb?: () => void) => WritableStreamRequiredeventNames
() => (string | symbol)[]RequiredgetMaxListeners
() => numberRequiredlistenerCount
(eventName: string | symbol, listener?: Function) => numberRequiredlisteners
(eventName: string | symbol) => Function[]RequiredprependListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredprependOnceListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredrawListeners
(eventName: string | symbol) => Function[]RequiredremoveListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredwrite
(buffer: string | Uint8Array, cb?: (err?: null | Error) => void) => boolean(str: string, encoding?: BufferEncoding, cb?: (err?: null | Error) => void) => booleanRequiredpipeline(stream1
, stream2
, ...streams
): WritableStream
Parameters
Returns
writable
booleanRequiredaddListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredemit
(eventName: string | symbol, ...args: any[]) => booleanRequiredend
(cb?: () => void) => WritableStream(data: string | Uint8Array, cb?: () => void) => WritableStream(str: string, encoding?: BufferEncoding, cb?: () => void) => WritableStreamRequiredeventNames
() => (string | symbol)[]RequiredgetMaxListeners
() => numberRequiredlistenerCount
(eventName: string | symbol, listener?: Function) => numberRequiredlisteners
(eventName: string | symbol) => Function[]RequiredprependListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredprependOnceListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredrawListeners
(eventName: string | symbol) => Function[]RequiredremoveListener
(eventName: string | symbol, listener: (...args: any[]) => void) => WritableStreamRequiredwrite
(buffer: string | Uint8Array, cb?: (err?: null | Error) => void) => boolean(str: string, encoding?: BufferEncoding, cb?: (err?: null | Error) => void) => booleanRequiredsetDefaultHighWaterMark
setDefaultHighWaterMark(objectMode
, value
): void
Sets the default highWaterMark used by streams.
Parameters
objectMode
booleanRequiredvalue
numberRequiredReturns
void
void
voidSince
v19.9.0