Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bufferedData being larger than maxBuffer #89

Merged
merged 2 commits into from
Aug 11, 2023
Merged

Fix bufferedData being larger than maxBuffer #89

merged 2 commits into from
Aug 11, 2023

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Aug 10, 2023

error.bufferedData should be limited by options.maxBuffer, just like the return value is. This PR fixes this.

index.js Outdated
@@ -39,12 +39,13 @@ const getStreamContents = async (stream, {convertChunk, getSize, getContents}, {
for await (const chunk of stream) {
const chunkType = getChunkType(chunk);
const convertedChunk = convertChunk[chunkType](chunk, textDecoder);
chunks.push(convertedChunk);
length += getSize(convertedChunk);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the length be wrong here for the bufferedData on the error? Since when there is a MaxBufferError we skip the new chunks, but we still included the chunk size in the length sum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!
Fixed in 35327d0

The test was not catching this because it was using getStream(), which does not use length to concatenate all chunks. I switched it to getStreamAsBuffer(), and the test was now failing. It is passing now.

@sindresorhus sindresorhus merged commit a0dcf80 into sindresorhus:main Aug 11, 2023
3 checks passed
@ehmicky ehmicky deleted the fix-buffered-data-length branch August 11, 2023 00:51
@ehmicky ehmicky mentioned this pull request Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants