From 4832d1c02c8caf3269c5e3f7bfe750f65885c34c 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 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- doc/api/stream.md | 29 +++++++++- lib/internal/streams/readable.js | 15 +++-- lib/internal/streams/utils.js | 11 ++++ 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, 169 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 047e1687d2e580..f002b4af8f7316 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1261,16 +1261,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.Readable.toWeb(streamReadable)`