Skip to content

Commit a8fed4e

Browse files
authored
Return empty a empty stream for zero sized blob (#86)
Return empty a empty stream for zero sized blob
1 parent 483973c commit a8fed4e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
## next
5+
- Fixed a bug where in BlobDataItem when the file was empty (#86)
6+
7+
## v2.1.2
8+
- Fixed a bug where `start` in BlobDataItem was undefined (#85)
9+
410
## v2.1.1
511
- Add nullish values checking in Symbol.hasInstance (#82)
612
- Add generated typings for from.js file (#80)

from.js

+4
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

+6
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)