azure-kusto-ingest
Version:
Azure Data Explorer Ingestion SDK
37 lines • 1.85 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import zlib from "zlib";
import { CompressionType, StreamDescriptor } from "./descriptors.js";
import { FileDescriptor } from "./fileDescriptor.js";
import { fileToStream } from "./streamUtils.js";
import { KustoStreamingIngestClientBase } from "./streamingIngestClientBase.js";
class KustoStreamingIngestClient extends KustoStreamingIngestClientBase {
constructor(kcsb, defaultProps, autoCorrectEndpoint) {
super(kcsb, defaultProps, autoCorrectEndpoint);
}
/**
* Use Readable for Node.js and ArrayBuffer in browser
*/
async ingestFromStream(stream, ingestionProperties, clientRequestId) {
var _a;
this.ensureOpen();
const props = this._getMergedProps(ingestionProperties);
const descriptor = stream instanceof StreamDescriptor ? stream : new StreamDescriptor(stream);
const compressedStream = descriptor.compressionType === CompressionType.None
? !(descriptor.stream instanceof ArrayBuffer)
? descriptor.stream.pipe(zlib.createGzip())
: descriptor.stream
: descriptor.stream;
return await this.kustoClient.executeStreamingIngest(props.database, props.table, compressedStream, props.format, (_a = props.ingestionMappingReference) !== null && _a !== void 0 ? _a : null, undefined, clientRequestId);
}
/**
* Use string for Node.js and Blob in browser
*/
async ingestFromFile(file, ingestionProperties) {
this.ensureOpen();
const descriptor = file instanceof FileDescriptor ? file : new FileDescriptor(file);
return this.ingestFromStream(await fileToStream(descriptor), ingestionProperties);
}
}
export default KustoStreamingIngestClient;
//# sourceMappingURL=streamingIngestClient.js.map