@azure-rest/ai-document-intelligence
Version:
Document Intelligence Rest Client
33 lines • 1.05 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { RestError } from "@azure/core-rest-pipeline";
/**
* Converts a NodeJS.ReadableStream to a Uint8Array.
*/
export 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 RestError(`Error reading response as text: ${e.message}`, {
code: RestError.PARSE_ERROR,
}));
}
});
});
}
//# sourceMappingURL=utils.js.map