@itwin/object-storage-core
Version:
Core generic object storage interfaces
53 lines • 2.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.streamToBufferFrontend = streamToBufferFrontend;
exports.streamToTransferTypeFrontend = streamToTransferTypeFrontend;
exports.downloadFromUrlFrontend = downloadFromUrlFrontend;
exports.uploadToUrlFrontend = uploadToUrlFrontend;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const axios_1 = require("axios");
async function streamToBufferFrontend(stream) {
return new Response(stream).arrayBuffer();
}
async function streamToTransferTypeFrontend(stream, transferType) {
switch (transferType) {
case "buffer":
return streamToBufferFrontend(stream);
case "stream":
return stream;
default:
throw new Error(`Type '${transferType === undefined ? "undefined" : transferType}' is not supported`);
}
}
async function downloadFromUrlFrontend(input, headers) {
const { transferType, url } = input;
switch (transferType) {
case "buffer":
const bufferResponse = await axios_1.default.get(url, {
responseType: "arraybuffer",
headers,
});
return bufferResponse.data;
case "stream":
// https://github.com/axios/axios/issues/479
const blobResponse = await axios_1.default.get(url, {
responseType: "blob",
headers,
});
return blobResponse.data.stream();
default:
throw new Error(`Type '${transferType === undefined ? "undefined" : transferType}' is not supported`);
}
}
async function uploadToUrlFrontend(url, data, method, headers) {
await axios_1.default.request({
url,
method,
data,
headers,
});
}
//# sourceMappingURL=Helpers.js.map
;