From 0026d7dc65e67e52b932fb2fbd8e6b3ec226ca99 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Sun, 12 Jul 2020 00:12:16 -0700 Subject: [PATCH 1/2] create test illustrating a bug --- test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test.js b/test.js index 52fdb72..ae73beb 100644 --- a/test.js +++ b/test.js @@ -114,6 +114,12 @@ test('Blob slice(0, -1)', async t => { t.is(await blob.text(), 'abcdefg'); }); +test('Blob(["hello ", "world"]).slice(5)', async t => { + const parts = ['hello ', 'world']; + const blob = new Blob(parts); + t.is(await blob.slice(5).text(), ' world'); +}); + test('throw away unwanted parts', async t => { const blob = new Blob(['a', 'b', 'c']).slice(1, 2); t.is(await blob.text(), 'b'); From 6bb57aa45bd5f4d345b31fea96276ea77b4ff6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Fri, 24 Jul 2020 01:52:36 +0200 Subject: [PATCH 2/2] fix slice test `added` bytes was calculated wrong --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a6954ce..65331aa 100644 --- a/index.js +++ b/index.js @@ -138,7 +138,7 @@ class Blob { } else { const chunk = part.slice(relativeStart, Math.min(size, relativeEnd)); blobParts.push(chunk); - added += size; + added += ArrayBuffer.isView(chunk) ? chunk.byteLength : chunk.size; relativeStart = 0; // All next sequental parts should start at 0 // don't add the overflow to new blobParts