aboutsummaryrefslogtreecommitdiff
path: root/ext/js/media/media-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/media/media-util.js')
-rw-r--r--ext/js/media/media-util.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/js/media/media-util.js b/ext/js/media/media-util.js
index 11172c5c..f783038a 100644
--- a/ext/js/media/media-util.js
+++ b/ext/js/media/media-util.js
@@ -129,4 +129,20 @@ class MediaUtil {
return null;
}
}
+
+ /**
+ * Creates a new `Blob` object from a base64 string of content.
+ * @param content The binary content string encoded in base64.
+ * @param mediaType The type of the media.
+ * @returns A new `Blob` object corresponding to the specified content.
+ */
+ static createBlobFromBase64Content(content, mediaType) {
+ 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 new Blob([array.buffer], {type: mediaType});
+ }
}