Skip to content

Commit

Permalink
src: fix creating an ArrayBuffer from a Blob created with openAsBlob
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong <[email protected]>
  • Loading branch information
daeyeon committed Apr 24, 2023
1 parent 23f4a6c commit 2b97826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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_ - start_);
}

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
8 changes: 8 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,14 @@ 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 data = await res.arrayBuffer();
strictEqual(res.size, data.byteLength);
})().then(common.mustCall());

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

0 comments on commit 2b97826

Please sign in to comment.