Skip to content

Return empty a empty stream for zero sized blob #86

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the changelog got out of sync with the actual changes. The changes mentioned in 2.1.1 were actually made in 2.1.2, so the next version would have what you currently mentioned in 2.1.2 and the actual 2.1.2 changes has to be taken from 2.1.1 section.

- 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