UNPKG

1.52 kBJavaScriptView Raw
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3import { __awaiter, __generator } from "tslib";
4import { gunzip, strFromU8 } from 'fflate';
5export var convert = function (stream) { return __awaiter(void 0, void 0, void 0, function () {
6 return __generator(this, function (_a) {
7 if (stream instanceof Blob || stream instanceof ReadableStream) {
8 return [2 /*return*/, new Response(stream)
9 .arrayBuffer()
10 .then(function (buffer) { return new Uint8Array(buffer); })];
11 }
12 else {
13 return [2 /*return*/, Promise.reject('Invalid content type')];
14 }
15 return [2 /*return*/];
16 });
17}); };
18export var base64ToArrayBuffer = function (base64) {
19 return Uint8Array.from(window.atob(base64), function (c) { return c.charCodeAt(0); });
20};
21export var gzipDecompressToString = function (data) { return __awaiter(void 0, void 0, void 0, function () {
22 return __generator(this, function (_a) {
23 switch (_a.label) {
24 case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
25 gunzip(data, function (err, resp) {
26 if (err)
27 reject(err);
28 else
29 resolve(strFromU8(resp));
30 });
31 })];
32 case 1: return [2 /*return*/, _a.sent()];
33 }
34 });
35}); };
36//# sourceMappingURL=utils.js.map
\No newline at end of file