feat: get wasm working from libparakeet

This commit is contained in:
鲁树人
2023-05-10 22:01:32 +01:00
parent 2c56c22c74
commit fc2238ff39
5 changed files with 206 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import { SelectFile } from './SelectFile';
import { FileListing } from './features/file-listing/FileListing';
import { Footer } from './Footer';
import { WasmTest } from './WasmTest';
function App() {
return (
@@ -14,6 +15,7 @@ function App() {
<Box mt="8">
<FileListing />
</Box>
{localStorage.__dev_test === '1' && <WasmTest />}
<Footer />
</Container>
</Box>

31
src/WasmTest.tsx Normal file
View File

@@ -0,0 +1,31 @@
import { LibParakeetInit, BlobSink, createArrayBufferReader } from '@jixun/libparakeet';
function testWasm() {
LibParakeetInit().then(async (mod) => {
const data = new Uint8Array(0x2000);
for (let i = 0; i < data.byteLength; i++) {
data[i] = i & 0xff;
}
const src = createArrayBufferReader(data, mod);
const sink = new BlobSink(mod);
mod.rw_test(sink.getWriter(), src);
const collected = sink.collectBlob();
const copied = await collected.arrayBuffer();
const copiedView = new Uint8Array(copied);
for (let i = 0; i < copied.byteLength; i++) {
if (copiedView[i] !== (i & 0xff)) {
alert(`validate at pos ${i} failed`);
return;
}
}
alert('wasm validate ok!');
});
}
export function WasmTest() {
return (
<button onClick={testWasm} type="button">
Test WASM
</button>
);
}