Skip to content

Commit

Permalink
Return empty a empty stream for zero sized blob (#86)
Browse files Browse the repository at this point in the history
Return empty a empty stream for zero sized blob
  • Loading branch information
jimmywarting authored Apr 29, 2021
1 parent 483973c commit a8fed4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## next
- Fixed a bug where in BlobDataItem when the file was empty (#86)

## v2.1.2
- Fixed a bug where `start` in BlobDataItem was undefined (#85)

## v2.1.1
- Add nullish values checking in Symbol.hasInstance (#82)
- Add generated typings for from.js file (#80)
Expand Down
4 changes: 4 additions & 0 deletions from.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class BlobDataItem {
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');
}

if (!this.size) {
return new Blob().stream();
}

return createReadStream(this.path, {
start: this.start,
end: this.start + this.size - 1
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ test('Reading from the stream created by blobFrom', async t => {
t.is(actual, expected);
});

test('Reading empty blobs', async t => {
const blob = blobFrom('./LICENSE').slice(0, 0);
const actual = await blob.text();
t.is(actual, '');
});

test('Blob-ish class is an instance of Blob', t => {
class File {
stream() {}
Expand Down

0 comments on commit a8fed4e

Please sign in to comment.