Skip to content

Return empty a empty stream for zero sized blob #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

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