@itwin/object-storage-google
Version:
Object storage implementation using Google Cloud Storage
50 lines • 2.76 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoogleClientStorage = void 0;
const internal_1 = require("@itwin/object-storage-core/lib/common/internal");
const internal_2 = require("@itwin/object-storage-core/lib/server/internal");
const object_storage_core_1 = require("@itwin/object-storage-core");
class GoogleClientStorage extends object_storage_core_1.ClientStorage {
_storageFactory;
constructor(_storageFactory) {
super();
this._storageFactory = _storageFactory;
}
async download(input) {
if ((0, internal_1.instanceOfUrlTransferInput)(input))
return await (0, internal_2.downloadFromUrl)(input);
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
if (input.transferType === "local") {
(0, internal_2.assertLocalFile)(input.localPath);
}
const storage = this._storageFactory.createFromToken(input.transferConfig);
const downloadBuffer = await storage.downloadFile(input.reference, input.localPath);
if (input.transferType === "local")
return input.localPath;
return (0, internal_2.bufferToTransferType)(downloadBuffer, input.transferType);
}
async upload(input) {
const isUrlTransfer = (0, internal_1.instanceOfUrlTransferInput)(input);
if (!isUrlTransfer)
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
if (typeof input.data === "string")
await (0, internal_2.assertFileNotEmpty)(input.data);
if (isUrlTransfer)
return (0, internal_2.uploadToUrl)(input.url, input.data, input.metadata);
const storage = this._storageFactory.createFromToken(input.transferConfig);
await storage.uploadFile(input.reference, input.data, input.metadata);
}
async uploadInMultipleParts(input) {
(0, internal_1.assertRelativeDirectory)(input.reference.relativeDirectory);
if (typeof input.data === "string")
await (0, internal_2.assertFileNotEmpty)(input.data);
const storage = this._storageFactory.createFromToken(input.transferConfig);
await storage.uploadFile(input.reference, input.data, input.options?.metadata, undefined, input.options?.partSize);
}
}
exports.GoogleClientStorage = GoogleClientStorage;
//# sourceMappingURL=GoogleClientStorage.js.map