2024-05-12 00:35:29 +02:00
|
|
|
import "./wasm_exec_memfs.js";
|
|
|
|
|
import fs from "node:fs";
|
|
|
|
|
|
2023-10-18 23:56:56 +02:00
|
|
|
import path from "path";
|
2024-01-12 18:39:57 +01:00
|
|
|
import { fileURLToPath } from 'url';
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
const nodeWasmLocation = path.join(__dirname, "../../../public/wasm/pdfcpu/", "pdfcpu.wasm");
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
export async function oneToOne(wasmArray, snapshot) {
|
|
|
|
|
const go = new Go();
|
|
|
|
|
go.argv = wasmArray;
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
const wasmFile = fs.readFileSync(nodeWasmLocation);
|
|
|
|
|
const webAssemblyInstantiatedSource = await WebAssembly.instantiate(wasmFile, go.importObject);
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
await globalThis.fs.promises.writeFile("/input.pdf", Buffer.from(snapshot));
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
await go.run(webAssemblyInstantiatedSource.instance);
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
globalThis.fs.promises.unlink("/input.pdf");
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
const pdfcpu_result = await globalThis.fs.promises.readFile("/output.pdf");
|
2023-10-18 23:56:56 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
globalThis.fs.promises.unlink("/output.pdf");
|
2023-10-21 20:10:07 +02:00
|
|
|
|
2024-05-12 00:35:29 +02:00
|
|
|
return new Uint8Array(pdfcpu_result);
|
2023-10-18 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function manyToOne() {
|
2023-10-21 18:08:41 +02:00
|
|
|
//TODO: Do this if necessary for some pdfcpu operations
|
2023-10-18 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function oneToMany() {
|
2023-10-21 18:08:41 +02:00
|
|
|
//TODO: Do this if necessary for some pdfcpu operations
|
2023-10-18 23:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function manyToMany() {
|
2023-10-21 18:08:41 +02:00
|
|
|
//TODO: Do this if necessary for some pdfcpu operations
|
2023-10-18 23:56:56 +02:00
|
|
|
}
|