-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob64.js
30 lines (30 loc) · 1.05 KB
/
blob64.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
var Blob64 = (function () {
function Blob64() {
}
Blob64.serialize = function (blob, onFinish) {
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function () {
onFinish(reader.result);
};
};
Blob64.deserialize = function (str) {
var indexOfComma = str.lastIndexOf(",");
var contentType = str.substr(0, indexOfComma + 1) || "";
var byteChars = atob(str.substr(indexOfComma + 1));
var sliceSize = 512;
var byteArrays = [];
for (var offset = 0; offset < byteChars.length; offset += sliceSize) {
var slice = byteChars.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
byteArrays.push(new Uint8Array(byteNumbers));
}
return new Blob(byteArrays, { type: contentType });
};
return Blob64;
}());
exports.Blob64 = Blob64;