1 |
|
2 |
|
3 | import { __awaiter, __generator } from "tslib";
|
4 | import { decode } from 'base-64';
|
5 | import { ungzip } from 'pako';
|
6 | export var convert = function (stream) { return __awaiter(void 0, void 0, void 0, function () {
|
7 | return __generator(this, function (_a) {
|
8 | if (!(stream instanceof Blob)) {
|
9 | return [2 , Promise.reject('Invalid content type')];
|
10 | }
|
11 | return [2 , new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
12 | var fileReaderInstance_1;
|
13 | return __generator(this, function (_a) {
|
14 | try {
|
15 | fileReaderInstance_1 = new FileReader();
|
16 | fileReaderInstance_1.readAsDataURL(stream);
|
17 | fileReaderInstance_1.onload = function () { return __awaiter(void 0, void 0, void 0, function () {
|
18 | var blobURL, base64Blob, decodedArrayBuffer;
|
19 | return __generator(this, function (_a) {
|
20 | blobURL = fileReaderInstance_1.result;
|
21 | base64Blob = blobURL.split(/,(.*)/s)[1];
|
22 | decodedArrayBuffer = base64ToArrayBuffer(base64Blob);
|
23 | resolve(decodedArrayBuffer);
|
24 | return [2 ];
|
25 | });
|
26 | }); };
|
27 | }
|
28 | catch (error) {
|
29 | reject('unable to convert blob to arrayBuffer: ' + error);
|
30 | }
|
31 | return [2 ];
|
32 | });
|
33 | }); })];
|
34 | });
|
35 | }); };
|
36 | export var base64ToArrayBuffer = function (base64) {
|
37 | var binaryString = decode(base64);
|
38 | return Uint8Array.from(binaryString, function (c) { return c.charCodeAt(0); });
|
39 | };
|
40 | export var gzipDecompressToString = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
41 | return __generator(this, function (_a) {
|
42 | return [2 , new Promise(function (resolve, reject) {
|
43 | try {
|
44 | var result = ungzip(data, { to: 'string' });
|
45 | resolve(result);
|
46 | }
|
47 | catch (error) {
|
48 | reject('unable to decompress' + error);
|
49 | }
|
50 | })];
|
51 | });
|
52 | }); };
|
53 |
|
\ | No newline at end of file |