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 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');