Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Return empty a empty stream for zero sized blob
  • Loading branch information
jimmywarting committed Apr 26, 2021
commit ac3462436b2396313ce48a538a95c4f44baba15a
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