Skip to content

Commit ac34624

Browse files
committed
Return empty a empty stream for zero sized blob
1 parent 483973c commit ac34624

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

from.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class BlobDataItem {
4343
throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError');
4444
}
4545

46+
if (!this.size) {
47+
return new Blob().stream();
48+
}
49+
4650
return createReadStream(this.path, {
4751
start: this.start,
4852
end: this.start + this.size - 1

test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ test('Reading from the stream created by blobFrom', async t => {
172172
t.is(actual, expected);
173173
});
174174

175+
test('Reading empty blobs', async t => {
176+
const blob = blobFrom('./LICENSE').slice(0, 0);
177+
const actual = await blob.text();
178+
t.is(actual, '');
179+
});
180+
175181
test('Blob-ish class is an instance of Blob', t => {
176182
class File {
177183
stream() {}

0 commit comments

Comments
 (0)