From 928148ac52540137b543e20d4005315295590df9 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 30 Apr 2024 11:27:32 -0700 Subject: [PATCH] fix(types): netstring decode --- packages/internal/src/netstring.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/internal/src/netstring.js b/packages/internal/src/netstring.js index 1e938bd35072..dffb05f58b16 100644 --- a/packages/internal/src/netstring.js +++ b/packages/internal/src/netstring.js @@ -43,10 +43,13 @@ export function netstringEncoderStream() { return new Transform({ transform, writableObjectMode: true }); } -// Input is a Buffer containing zero or more netstrings and maybe some -// leftover bytes. Output is zero or more decoded Buffers, one per netstring, -// plus a Buffer of leftover bytes. -// +/** + * + * @param {Buffer} data containing zero or more netstrings and maybe some + * leftover bytes + * @param {number} [optMaxChunkSize] + * @returns {{ leftover: Buffer, payloads: Buffer[] }} zero or more decoded Buffers, one per netstring, + */ export function decode(data, optMaxChunkSize) { // TODO: it would be more efficient to accumulate pending data in an array, // rather than doing a concat each time @@ -81,6 +84,11 @@ export function decode(data, optMaxChunkSize) { return { leftover, payloads }; } +/** + * + * @param {number} [optMaxChunkSize ] + * @returns {Transform} + */ // input is a byte pipe, output is a sequence of Buffers export function netstringDecoderStream(optMaxChunkSize) { let buffered = Buffer.from('');