aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/sandbox/string-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/data/sandbox/string-util.js')
-rw-r--r--ext/js/data/sandbox/string-util.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/js/data/sandbox/string-util.js b/ext/js/data/sandbox/string-util.js
index 37e021c9..b523c39d 100644
--- a/ext/js/data/sandbox/string-util.js
+++ b/ext/js/data/sandbox/string-util.js
@@ -58,4 +58,19 @@ class StringUtil {
return binary;
}
}
+
+ /**
+ * Converts a base64 string to an ArrayBuffer.
+ * @param content The binary content string encoded in base64.
+ * @returns A new `ArrayBuffer` object corresponding to the specified content.
+ */
+ static base64ToArrayBuffer(content) {
+ const binaryContent = atob(content);
+ const length = binaryContent.length;
+ const array = new Uint8Array(length);
+ for (let i = 0; i < length; ++i) {
+ array[i] = binaryContent.charCodeAt(i);
+ }
+ return array.buffer;
+ }
}