Skip to content

Commit 2b97826

Browse files
committed
src: fix creating an ArrayBuffer from a Blob created with openAsBlob
Signed-off-by: Daeyeon Jeong <[email protected]>
1 parent 23f4a6c commit 2b97826

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/dataqueue/queue.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ class FdEntry final : public EntryImpl {
817817
uint64_t new_start = start_ + start;
818818
uint64_t new_end = end_;
819819
if (end.has_value()) {
820-
new_end = std::min(end.value() + start, new_end);
820+
new_end = std::min(end.value(), end_ - start_);
821821
}
822822

823823
CHECK(new_start >= start_);
@@ -881,7 +881,7 @@ class FdEntry final : public EntryImpl {
881881
file,
882882
Local<Object>(),
883883
entry->start_,
884-
entry->end_)),
884+
entry->end_ - entry->start_)),
885885
entry);
886886
}
887887

test/parallel/test-blob-file-backed.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ writeFileSync(testfile3, '');
6767
await unlink(testfile);
6868
})().then(common.mustCall());
6969

70+
(async () => {
71+
// Refs: https://github.com/nodejs/node/issues/47683
72+
const blob = await openAsBlob(testfile);
73+
const res = blob.slice(10, 20);
74+
const data = await res.arrayBuffer();
75+
strictEqual(res.size, data.byteLength);
76+
})().then(common.mustCall());
77+
7078
(async () => {
7179
const blob = await openAsBlob(testfile2);
7280
const stream = blob.stream();

0 commit comments

Comments
 (0)