fix(netstring): reader avoid copy when chunked separator
MODIFY
packages/netstring/reader.js
packages/netstring/reader.js
@@ -95,8 +95,12 @@ async function* makeNetstringIterator(input, { name = '<unknown>' } = {}) {
lengthBuffer = [];
yield data;
} else if (buffer.length) {
+ if (!dataBuffer && buffer.length === remainingDataLength) {
+ dataBuffer = buffer;
+ } else {
dataBuffer = dataBuffer || new Uint8Array(remainingDataLength);
dataBuffer.set(buffer, dataBuffer.length - remainingDataLength);
+ }
remainingDataLength -= buffer.length;
buffer = buffer.subarray(buffer.length);
}

MODIFY
packages/netstring/test/test-netstring.js
packages/netstring/test/test-netstring.js
@@ -64,7 +64,7 @@ test(
test(
'read messages divided over chunk boundaries',
readChunkedMessage,
- ['5:hel', 'lo,5:world,8:good ', 'bye,'],
+ ['5:hello', ',5:world,8:good ', 'bye,'],
['hello', 'world', 'good bye'],
);

fix(netstring): reader avoid copy when chunked separator