From 1661ca59471449f48bbb2f73fed4eac497050f96 Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Fri, 2 Nov 2018 03:17:22 +0100 Subject: [PATCH] Bugfix for working on Safari In Safari, the Uint8Array constructor behaves differently than in other browsers. ```js const a = new Uint8Array(buf, undefined, undefined); // the result "a" will have zero length no matter buf.byteLength. ``` --- src/base64-arraybuffer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/base64-arraybuffer.js b/src/base64-arraybuffer.js index 3ee7411..46de6b4 100644 --- a/src/base64-arraybuffer.js +++ b/src/base64-arraybuffer.js @@ -15,7 +15,8 @@ for (let i = 0; i < chars.length; i++) { } export const encode = function (arraybuffer, byteOffset, length) { - const bytes = new Uint8Array(arraybuffer, byteOffset, length), + if (length == null) length = arraybuffer.byteLength; // Needed for Safari + const bytes = new Uint8Array(arraybuffer, byteOffset || 0 /* Needed for Safari */, length), len = bytes.length; let base64 = '';