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

src: fix creating an ArrayBuffer from a Blob created with openAsBlob #47691

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dataqueue/queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class FdEntry final : public EntryImpl {
uint64_t new_start = start_ + start;
uint64_t new_end = end_;
if (end.has_value()) {
new_end = std::min(end.value() + start, new_end);
new_end = std::min(end.value(), end_);
}

CHECK(new_start >= start_);
Expand Down Expand Up @@ -881,7 +881,7 @@ class FdEntry final : public EntryImpl {
file,
Local<Object>(),
entry->start_,
entry->end_)),
entry->end_ - entry->start_)),
entry);
}

Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-blob-file-backed.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ writeFileSync(testfile3, '');
await unlink(testfile);
})().then(common.mustCall());

(async () => {
// Refs: https://github.com/nodejs/node/issues/47683
const blob = await openAsBlob(testfile);
const res = blob.slice(10, 20);
const ab = await res.arrayBuffer();
strictEqual(res.size, ab.byteLength);

let length = 0;
const stream = await res.stream();
for await (const chunk of stream)
length += chunk.length;
strictEqual(res.size, length);

const res1 = blob.slice(995, 1005);
strictEqual(await res1.text(), data.slice(995, 1005));
})().then(common.mustCall());

(async () => {
const blob = await openAsBlob(testfile2);
const stream = blob.stream();
Expand Down