@itwin/object-storage-azure
Version:
Object storage implementation using Azure Blob Storage
60 lines • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockBlobClientWrapper = void 0;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const stream_1 = require("stream");
class BlockBlobClientWrapper {
_client;
constructor(_client) {
this._client = _client;
}
getBlobHTTPHeaders(headers) {
return headers === undefined
? undefined
: {
blobContentEncoding: headers.contentEncoding,
blobCacheControl: headers.cacheControl,
blobContentType: headers.contentType,
};
}
async download(options) {
const downloadResponse = await this._client.download(undefined, undefined, options);
return downloadResponse.readableStreamBody;
}
async upload(data, metadata, headers) {
const blobHTTPHeaders = this.getBlobHTTPHeaders(headers);
if (typeof data === "string")
await this._client.uploadFile(data, { metadata, blobHTTPHeaders });
else if (data instanceof stream_1.Readable)
await this._client.uploadStream(data, undefined, undefined, {
metadata,
blobHTTPHeaders,
});
else
await this._client.upload(data, data.byteLength, {
metadata,
blobHTTPHeaders,
});
}
async uploadInMultipleParts(data, options, headers) {
const blobHTTPHeaders = this.getBlobHTTPHeaders(headers);
const { metadata, partSize, queueSize } = options ?? {};
if (data instanceof stream_1.Readable)
await this._client.uploadStream(data, partSize, queueSize, {
metadata,
blobHTTPHeaders,
});
else
await this._client.uploadFile(data, {
metadata,
blockSize: partSize,
concurrency: queueSize,
blobHTTPHeaders,
});
}
}
exports.BlockBlobClientWrapper = BlockBlobClientWrapper;
//# sourceMappingURL=BlockBlobClientWrapper.js.map