UNPKG

@azure-rest/ai-document-intelligence

Version:
36 lines 1.22 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.streamToUint8Array = streamToUint8Array; const core_rest_pipeline_1 = require("@azure/core-rest-pipeline"); /** * Converts a NodeJS.ReadableStream to a Uint8Array. */ function streamToUint8Array(stream) { return new Promise((resolve, reject) => { const chunks = []; stream.on("data", (chunk) => { if (Buffer.isBuffer(chunk)) { chunks.push(chunk); } else { chunks.push(Buffer.from(chunk)); } }); stream.on("end", () => { resolve(new Uint8Array(Buffer.concat(chunks))); }); stream.on("error", (e) => { if (e && (e === null || e === void 0 ? void 0 : e.name) === "AbortError") { reject(e); } else { reject(new core_rest_pipeline_1.RestError(`Error reading response as text: ${e.message}`, { code: core_rest_pipeline_1.RestError.PARSE_ERROR, })); } }); }); } //# sourceMappingURL=utils.js.map