Stop blindly extracting uint8array.buffer after calling compress() #5753
+28
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a node zlib based compression / decompression code path in gz.ts. This path is currently not exercised by our tests. But if I change our Jest environment so that it exercises the node zlib code path, there are test failures in receive-profile.test.ts, for two reasons:
compress/decompresswere discarding thebyteOffsetandbyteLengthof the returned typed array and re-wrapping the entire underlying ArrayBuffer, including potential garbage bytes at the start or at the end. (In practice just at the end.)receive-profile.test.tswere accessing.bufferon the array returned bycompress(), and assuming that the buffer didn't contain any extra data beyond the Uint8Array.So this fix removes the rewrapping, and replaces each of those
.bufferaccesses with a potential copy if that's needed to make sure that the ArrayBuffer doesn't contain any extra data.A cleaner solution might be to stop using ArrayBuffer so much in these tests, but in some of them we simulate the response from a fetch() which definitely has an arrayBuffer() accessor and not a byteArray() accessor.