From 890b46b697c43c5102fc7640569bc83ec52b7c68 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sat, 18 Feb 2023 11:27:32 +0100 Subject: [PATCH] chore(read-chunk): add JSDoc --- @vates/read-chunk/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/@vates/read-chunk/index.js b/@vates/read-chunk/index.js index fcede1035..8aea1c59f 100644 --- a/@vates/read-chunk/index.js +++ b/@vates/read-chunk/index.js @@ -1,5 +1,12 @@ 'use strict' +/** + * Read a chunk of data from a stream. + * + * @param {Readable} stream - A readable stream to read from. + * @param {number} size - The number of bytes to read. + * @returns {Promise} - A Promise that resolves to a Buffer of up to size bytes if available, or null if end of stream is reached. The Promise is rejected if there is an error while reading from the stream. + */ const readChunk = (stream, size) => stream.closed || stream.readableEnded ? Promise.resolve(null) @@ -33,6 +40,13 @@ const readChunk = (stream, size) => }) exports.readChunk = readChunk +/** + * Read a chunk of data from a stream. + * + * @param {Readable} stream - A readable stream to read from. + * @param {number} size - The number of bytes to read. + * @returns {Promise} - A Promise that resolves to a Buffer of size bytes. The Promise is rejected if there is an error while reading from the stream. + */ exports.readChunkStrict = async function readChunkStrict(stream, size) { const chunk = await readChunk(stream, size) if (chunk === null) {