From b8f5fb94219e69baba3962ba9f1d7c29d1046026 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 30 Jul 2021 14:17:25 +0200 Subject: [PATCH] stream: add readableDidRead Adds did read accessor used to determine whether a readable has been read from. Refs: https://github.com/nodejs/undici/pull/907 --- doc/api/stream.md | 11 ++ lib/internal/streams/readable.js | 19 ++- test/parallel/test-stream-readable-didRead.js | 109 ++++++++++++++++++ 3 files changed, 138 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 d616bb78bccfd0..dd46e8fa761e62 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1222,6 +1222,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`