From ac621ff5e76469db2ec97d0b1d48c765a5fd29de 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/_http_incoming.js | 1 - lib/_http_server.js | 2 +- lib/internal/streams/readable.js | 19 ++-- test/parallel/test-stream-readable-didRead.js | 98 +++++++++++++++++-- 5 files changed, 112 insertions(+), 19 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index fc66885ebc9203..312f200e61c4d5 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1261,6 +1261,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`