From 26562d874bb4152c29934f6b98fc2c001df2eef0 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 23 Jan 2022 19:38:41 +0100 Subject: [PATCH] Explicitly close the stream once finished reading --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5a7dfd2..45165ef 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,11 @@ function doRead(handle, length) { }).then((result) => { if (result.bytesRead === 0) { // Not documented; https://github.com/nodejs/node/issues/35363 - throw new EndOfStream(); + return Promise.try(() => { + return handle.close(); + }).then(() => { + throw new EndOfStream(); + }); } else if (result.bytesRead === length) { return buffer; } else if (result.bytesRead < length) {