Skip to content

Commit c421761

Browse files
daeyeontargos
authored andcommitted
src: fix creating an ArrayBuffer from a Blob created with openAsBlob
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com> PR-URL: #47691 Fixes: #47683 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4bc17fd commit c421761

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/dataqueue/queue.cc

+2-2
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_);
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

+17
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ writeFileSync(testfile3, '');
6868
await unlink(testfile);
6969
})().then(common.mustCall());
7070

71+
(async () => {
72+
// Refs: https://github.com/nodejs/node/issues/47683
73+
const blob = await openAsBlob(testfile);
74+
const res = blob.slice(10, 20);
75+
const ab = await res.arrayBuffer();
76+
strictEqual(res.size, ab.byteLength);
77+
78+
let length = 0;
79+
const stream = await res.stream();
80+
for await (const chunk of stream)
81+
length += chunk.length;
82+
strictEqual(res.size, length);
83+
84+
const res1 = blob.slice(995, 1005);
85+
strictEqual(await res1.text(), data.slice(995, 1005));
86+
})().then(common.mustCall());
87+
7188
(async () => {
7289
const blob = await openAsBlob(testfile2);
7390
const stream = blob.stream();

0 commit comments

Comments
 (0)