From ac3462436b2396313ce48a538a95c4f44baba15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Mon, 26 Apr 2021 12:33:27 +0200 Subject: [PATCH 1/2] Return empty a empty stream for zero sized blob --- from.js | 4 ++++ test.js | 6 ++++++ 2 files changed, 10 insertions(+) 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() {} From d03f6cd5477b78d5b7bda0f42f9f5539b919f988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Mon, 26 Apr 2021 12:38:48 +0200 Subject: [PATCH 2/2] added a changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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)