diff --git a/CHANGELOG.md b/CHANGELOG.md index d71ce72..b1bb459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/from.js b/from.js index bdca282..ca94205 100644 --- a/from.js +++ b/from.js @@ -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 diff --git a/test.js b/test.js index a38c8fe..ebbfad9 100644 --- a/test.js +++ b/test.js @@ -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() {}