/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { createReadStream } from "node:fs"; import { readFile } from "node:fs/promises"; import { Readable } from "node:stream"; export function filesToStream(filePath: string): ReadableStream { return Readable.toWeb( createReadStream(filePath), ) as unknown as ReadableStream; } export async function filesToByteArray(filePath: string): Promise { return new Uint8Array(await readFile(filePath)); } export async function filesToString(filePath: string): Promise { return readFile(filePath, "utf8"); } export async function streamToByteArray( stream?: ReadableStream, ): Promise { if (!stream) { return Buffer.from(""); } const chunks = []; const reader = stream.getReader(); let done = false; while (!done) { const res = await reader.read(); done = res.done; if (res.value) { chunks.push(res.value); } } return Buffer.concat(chunks); } export function bytesToStream(bytes: Uint8Array): ReadableStream { return new ReadableStream({ start(controller) { controller.enqueue(bytes); }, pull(controller) { controller.close(); }, cancel() { }, }); }