-
Notifications
You must be signed in to change notification settings - Fork 2
/
adv_worker.ts
60 lines (56 loc) · 2.07 KB
/
adv_worker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { File, ready, Group, Dataset, BrokenSoftLink, ExternalLink } from "h5wasm";
import { createLazyFile } from './lazyFileLRU';
export type {};
declare var self: MyWorkerGlobalScope;
interface MyWorkerGlobalScope extends Worker {
file: File;
import: object;
}
var file: File;
const DEMO_FILEPATH="https://ncnr.nist.gov/pub/ncnrdata/ngbsans/202009/nonims294/data/sans114140.nxs.ngb?gzip=false";
self.onmessage = async function (event) {
const { action, payload } = event.data;
if (action === "load") {
const url = payload?.url ?? DEMO_FILEPATH;
const requestChunkSize = payload?.requestChunkSize ?? 1024 * 1024;
const LRUSize = payload?.LRUSize ?? 50;
const { FS } = await ready;
const config = {
rangeMapper: (fromByte: number, toByte: number) => ({url, fromByte, toByte}),
requestChunkSize,
LRUSize
}
//hdf5.FS.createLazyFile('/', "current.h5", DEMO_FILEPATH, true, false);
createLazyFile(FS, '/', 'current.h5', true, false, config);
file = new File("current.h5");
}
else if (action === "get") {
await ready;
if (file) {
const path = payload?.path ?? "entry";
const item = file.get(path);
if (item instanceof Group) {
self.postMessage({
type: item.type,
attrs: item.attrs,
children: [...item.keys()]
});
} else if (item instanceof Dataset) {
const value = (payload.slice) ? item.slice(payload.slice) : item.value;
self.postMessage({
type: item.type,
attrs: item.attrs,
value
});
} else if (item instanceof BrokenSoftLink || item instanceof ExternalLink) {
self.postMessage(item);
}
else {
self.postMessage({
type: "error",
value: `item ${path} not found`
})
}
}
}
};