UNPKG

azure-kusto-ingest

Version:
39 lines 1.62 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import pako from "pako"; import { AbstractDescriptor, CompressionType, shouldCompressFileByExtension } from "./descriptors.js"; import { shouldCompressFileByFormat } from "./ingestionProperties.js"; export class FileDescriptor extends AbstractDescriptor { constructor(file, sourceId = null, size = null, compressionType = CompressionType.None, extension, name) { super(sourceId); this.file = file; this.extension = extension; this.name = name; this.compressionType = compressionType; this.size = size || file.size; this.zipped = compressionType !== CompressionType.None || this.extension === ".gz" || this.extension === ".zip"; this.shouldNotCompress = !shouldCompressFileByExtension(this.extension); } async prepare(ingestionProperties) { const shouldNotCompressByFormat = !shouldCompressFileByFormat(ingestionProperties); if (!this.zipped && !this.shouldNotCompress && !shouldNotCompressByFormat) { try { const gzipped = pako.gzip(await this.file.arrayBuffer()); return new Blob([gzipped]); } catch (e) { // Ignore - return the file itself } } return this.file; } async cleanup() { if (this.cleanupTmp) { await this.cleanupTmp(); } } getCompressionSuffix() { return this.compressionType ? `.${this.compressionType}` : ".gz"; } } //# sourceMappingURL=fileDescriptor.browser.js.map