From a62d4d60f42f1b57f8094086caa90f3495c1a9e6 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 30 Jul 2021 14:18:38 +0200 Subject: [PATCH] stream: add readableDidRead if has been read from Adds did read accessor used to determine whether a readable has been read from. PR-URL: https://github.com/nodejs/node/pull/39589 Refs: https://github.com/nodejs/undici/pull/907 Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum --- doc/api/stream.md | 11 ++ lib/internal/streams/readable.js | 19 +++- test/parallel/test-stream-readable-didRead.js | 104 ++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-stream-readable-didRead.js diff --git a/doc/api/stream.md b/doc/api/stream.md index 30e6062603a724..64045f01608121 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1211,6 +1211,17 @@ 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.readableDidRead` + + +* {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. + ##### `readable.readableEncoding`