@nuxthub/core
Version:
Build full-stack Nuxt applications, with zero configuration.
19 lines (18 loc) • 522 B
JavaScript
import mime from "mime";
export async function streamToArrayBuffer(stream, streamSize) {
const result = new Uint8Array(streamSize);
let bytesRead = 0;
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
result.set(value, bytesRead);
bytesRead += value.length;
}
return result;
}
export function getContentType(pathOrExtension) {
return pathOrExtension && mime.getType(pathOrExtension) || "application/octet-stream";
}