Skip to content

fix(BufferStream): add only the bytes of a typed array view in addBuffer - #620

Merged
wayfarer3130 merged 1 commit into
0.xfrom
fix/add-buffer-byte-offset
Nov 27, 2026
Merged

wayfarer3130 merged 1 commit into
0.xfrom
fix/add-buffer-byte-offset

Conversation

@wayfarer3130

Copy link
Copy Markdown
Contributor

Summary

This change fixes #619 for the 0.52 releases. SplitDataView.addBuffer now adds only the bytes of a typed array or a DataView, and not the full underlying ArrayBuffer.

Problem

SplitDataView.addBuffer replaced the argument with buffer.buffer, and ignored byteOffset and byteLength. ReadBufferStream.addBuffer and the ReadBufferStream constructor call this method. A small Node.js Buffer is a view of a shared pool. Thus each small Buffer added the full pool, with the bytes of other allocations, to the stream.

Changes

  • src/SplitDataView.js: for a view (ArrayBuffer.isView), addBuffer uses byteOffset as the base. options.start and options.end are relative to the start of the view. When the view covers its full ArrayBuffer, the method transfers the ArrayBuffer as before. Otherwise it copies the bytes of the view.
  • An ArrayBuffer argument has the same behaviour as before.
  • test/readBufferStream.test.js: two tests ("the API must do this"):
    • addBuffer with a Uint8Array view and a DataView of a larger ArrayBuffer adds only the bytes of each view.
    • The constructor with a view reads only the bytes of that view.

Compatibility

Before this change, options.start and options.end for a view were relative to the underlying ArrayBuffer. No caller in dcmjs gives a view together with these options. A caller outside dcmjs that gives a view with start and end must now give values relative to the view.

Tests

npx jest test/readBufferStream.test.js test/writeBufferStream.test.js   # 18 tests passed
npm test

Without the change in src/SplitDataView.js, the two new tests fail. npm test reports 3 failures in test/data.test.js (test_multiframe_1, test_oneslice_seg, test_deflated). The same 3 tests also fail on master without this change on my system.

A separate pull request makes the same fix on the 1.0-beta branch.

🤖 Generated with Claude Code

SplitDataView.addBuffer replaced a typed array or DataView with its full
underlying ArrayBuffer, and ignored byteOffset and byteLength. A small
Node.js Buffer is a view of a shared pool, so ReadBufferStream.addBuffer
and the ReadBufferStream constructor added bytes of other allocations.

Fixes #619

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit 9fd7c72
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6adfe93686e512f3398e0dd3
😎 Deploy Preview https://deploy-preview-620--dcmjs2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@wayfarer3130
wayfarer3130 marked this pull request as ready for review October 27, 2026 00:09
@wayfarer3130
wayfarer3130 merged commit 78fc61f into 0.x Nov 27, 2026
20 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/add-buffer-byte-offset branch November 27, 2026 22:44
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.54.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReadBufferStream.addBuffer adds the full ArrayBuffer of a typed array view, and ignores its byteOffset

1 participant