This commit is contained in:
26
docs/snippets/wasm/getting-started/async-extraction.ts
Normal file
26
docs/snippets/wasm/getting-started/async-extraction.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { extractBytes, getWasmCapabilities, initWasm } from "@kreuzberg/wasm";
|
||||
|
||||
async function extractDocuments(files: Uint8Array[], mimeTypes: string[]) {
|
||||
const caps = getWasmCapabilities();
|
||||
if (!caps.hasWasm) {
|
||||
throw new Error("WebAssembly not supported");
|
||||
}
|
||||
|
||||
await initWasm();
|
||||
|
||||
const results = await Promise.all(
|
||||
files.map((bytes, index) => extractBytes(bytes, mimeTypes[index])),
|
||||
);
|
||||
|
||||
return results.map((r) => ({
|
||||
content: r.content,
|
||||
pageCount: r.metadata?.pageCount,
|
||||
}));
|
||||
}
|
||||
|
||||
const fileBytes = [new Uint8Array([1, 2, 3])];
|
||||
const mimes = ["application/pdf"];
|
||||
|
||||
extractDocuments(fileBytes, mimes)
|
||||
.then((results) => console.log(results))
|
||||
.catch(console.error);
|
||||
Reference in New Issue
Block a user