From af7047a815ec8d9df824f6b293d2bb17c837c6bf Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 2 Aug 2021 13:08:32 +0200 Subject: [PATCH] stream: add isDisturbed helper Adds a helper util used to determine whether a stream has been disturbed (read or cancelled). Refs: https://github.com/nodejs/node/issues/39627 PR-URL: https://github.com/nodejs/node/pull/39628 Backport-PR-URL: https://github.com/nodejs/node/pull/39819 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- doc/api/stream.md | 29 +++++++++- lib/internal/streams/readable.js | 15 +++-- lib/internal/streams/utils.js | 13 +++++ lib/internal/webstreams/readablestream.js | 9 +++ lib/stream.js | 1 + test/parallel/test-stream-readable-aborted.js | 57 +++++++++++++++++++ test/parallel/test-stream-readable-didRead.js | 8 ++- test/parallel/test-whatwg-readablestream.js | 50 ++++++++++++++++ 8 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 test/parallel/test-stream-readable-aborted.js diff --git a/doc/api/stream.md b/doc/api/stream.md index d6707a7a84246e..79f524c152f3ce 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1259,16 +1259,27 @@ added: v11.4.0 Is `true` if it is safe to call [`readable.read()`][stream-read], which means the stream has not been destroyed or emitted `'error'` or `'end'`. +##### `readable.readableAborted` + + +> Stability: 1 - Experimental + +* {boolean} + +Returns whether the stream was destroyed or errored before emitting `'end'`. + ##### `readable.readableDidRead` +> Stability: 1 - Experimental + * {boolean} -Allows determining if the stream has been or is about to be read. -Returns true if `'data'`, `'end'`, `'error'` or `'close'` has been -emitted. +Returns whether `'data'` has been emitted. ##### `readable.readableEncoding` + +> Stability: 1 - Experimental + +* `stream` {stream.Readable|ReadableStream} +* Returns: `boolean` + +Returns whether the stream has been read from or cancelled. + ### `stream.addAbortSignal(signal, stream)`