omni-viewer-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/THIRD_PARTY_NOTICES.md +49 -0
- package/dist/assets/audio-engine/audio_engine.mjs +2 -0
- package/dist/assets/audio-engine/audio_engine.wasm +0 -0
- package/dist/assets/pdfjs/pdf.worker.min.mjs +21 -0
- package/dist/host/index.d.ts +133 -0
- package/dist/host/index.js +10 -0
- package/dist/i18n/catalog.en.d.ts +1 -0
- package/dist/i18n/catalog.en.js +411 -0
- package/dist/i18n/catalog.ko.d.ts +1 -0
- package/dist/i18n/catalog.ko.js +68 -0
- package/dist/i18n/index.d.ts +18 -0
- package/dist/i18n/index.js +41 -0
- package/dist/licenses/emscripten.txt +101 -0
- package/dist/licenses/kissfft.txt +28 -0
- package/dist/licenses/pdfjs-dist.txt +177 -0
- package/dist/parsers/a2l/index.d.ts +1 -0
- package/dist/parsers/a2l/index.js +1 -0
- package/dist/parsers/archive/index.d.ts +22 -0
- package/dist/parsers/archive/index.js +46 -0
- package/dist/parsers/archive/model.d.ts +29 -0
- package/dist/parsers/archive/model.js +1 -0
- package/dist/parsers/archive/worker.d.ts +21 -0
- package/dist/parsers/archive/worker.js +1 -0
- package/dist/parsers/arxml/index.d.ts +1 -0
- package/dist/parsers/arxml/index.js +1 -0
- package/dist/parsers/asc/index.d.ts +1 -0
- package/dist/parsers/asc/index.js +1 -0
- package/dist/parsers/audio/index.d.ts +9 -0
- package/dist/parsers/audio/index.js +46 -0
- package/dist/parsers/automotive/index.d.ts +33 -0
- package/dist/parsers/automotive/index.js +973 -0
- package/dist/parsers/blf/index.d.ts +1 -0
- package/dist/parsers/blf/index.js +1 -0
- package/dist/parsers/csv/delimiter.d.ts +31 -0
- package/dist/parsers/csv/delimiter.js +151 -0
- package/dist/parsers/csv/index.d.ts +30 -0
- package/dist/parsers/csv/index.js +108 -0
- package/dist/parsers/csv/parseText.d.ts +20 -0
- package/dist/parsers/csv/parseText.js +108 -0
- package/dist/parsers/csv/sort.d.ts +26 -0
- package/dist/parsers/csv/sort.js +224 -0
- package/dist/parsers/csv/statistics.d.ts +49 -0
- package/dist/parsers/csv/statistics.js +150 -0
- package/dist/parsers/dbc/index.d.ts +56 -0
- package/dist/parsers/dbc/index.js +94 -0
- package/dist/parsers/doc-binary/index.d.ts +35 -0
- package/dist/parsers/doc-binary/index.js +267 -0
- package/dist/parsers/doc-binary/vscode-parser.d.ts +142 -0
- package/dist/parsers/doc-binary/vscode-parser.js +3747 -0
- package/dist/parsers/excel/index.d.ts +17 -0
- package/dist/parsers/excel/index.js +406 -0
- package/dist/parsers/excel/model.d.ts +80 -0
- package/dist/parsers/excel/model.js +48 -0
- package/dist/parsers/excel/serialize.d.ts +3 -0
- package/dist/parsers/excel/serialize.js +78 -0
- package/dist/parsers/hdf5/index.d.ts +75 -0
- package/dist/parsers/hdf5/index.js +658 -0
- package/dist/parsers/hdf5/node.d.ts +21 -0
- package/dist/parsers/hdf5/node.js +95 -0
- package/dist/parsers/json/index.d.ts +15 -0
- package/dist/parsers/json/index.js +102 -0
- package/dist/parsers/json/model.d.ts +42 -0
- package/dist/parsers/json/model.js +140 -0
- package/dist/parsers/json/parse.d.ts +22 -0
- package/dist/parsers/json/parse.js +279 -0
- package/dist/parsers/json/tokenizer.d.ts +17 -0
- package/dist/parsers/json/tokenizer.js +175 -0
- package/dist/parsers/jsonl/index.d.ts +14 -0
- package/dist/parsers/jsonl/index.js +18 -0
- package/dist/parsers/jsonl/model.d.ts +23 -0
- package/dist/parsers/jsonl/model.js +1 -0
- package/dist/parsers/jsonl/parse.d.ts +7 -0
- package/dist/parsers/jsonl/parse.js +34 -0
- package/dist/parsers/markdown/index.d.ts +37 -0
- package/dist/parsers/markdown/index.js +59 -0
- package/dist/parsers/mat/index.d.ts +31 -0
- package/dist/parsers/mat/index.js +426 -0
- package/dist/parsers/mermaid/index.d.ts +5 -0
- package/dist/parsers/mermaid/index.js +3 -0
- package/dist/parsers/mf4/index.d.ts +1 -0
- package/dist/parsers/mf4/index.js +1 -0
- package/dist/parsers/parquet/index.d.ts +21 -0
- package/dist/parsers/parquet/index.js +68 -0
- package/dist/parsers/pcap/index.d.ts +1 -0
- package/dist/parsers/pcap/index.js +1 -0
- package/dist/parsers/pcapng/index.d.ts +1 -0
- package/dist/parsers/pcapng/index.js +1 -0
- package/dist/parsers/plantuml/index.d.ts +5 -0
- package/dist/parsers/plantuml/index.js +4 -0
- package/dist/parsers/ppt-binary/index.d.ts +5 -0
- package/dist/parsers/ppt-binary/index.js +62 -0
- package/dist/parsers/ppt-binary/pptBinaryBuildContext.d.ts +12 -0
- package/dist/parsers/ppt-binary/pptBinaryBuildContext.js +40 -0
- package/dist/parsers/ppt-binary/pptBinaryContainer.d.ts +4 -0
- package/dist/parsers/ppt-binary/pptBinaryContainer.js +174 -0
- package/dist/parsers/ppt-binary/pptBinaryTypes.d.ts +125 -0
- package/dist/parsers/ppt-binary/pptBinaryTypes.js +1 -0
- package/dist/parsers/ppt-binary/pptSlideLayouts.d.ts +9 -0
- package/dist/parsers/ppt-binary/pptSlideLayouts.js +510 -0
- package/dist/parsers/ppt-binary/vscode-parser.d.ts +116 -0
- package/dist/parsers/ppt-binary/vscode-parser.js +2853 -0
- package/dist/parsers/ppt-binary/vscode.d.ts +4 -0
- package/dist/parsers/ppt-binary/vscode.js +12 -0
- package/dist/parsers/pptx/index.d.ts +15 -0
- package/dist/parsers/pptx/index.js +88 -0
- package/dist/parsers/pptx/vscode-parser.d.ts +167 -0
- package/dist/parsers/pptx/vscode-parser.js +1503 -0
- package/dist/parsers/pptx/vscode.d.ts +4 -0
- package/dist/parsers/pptx/vscode.js +18 -0
- package/dist/parsers/pptx/zip-reader.d.ts +3 -0
- package/dist/parsers/pptx/zip-reader.js +20 -0
- package/dist/parsers/proto/index.d.ts +90 -0
- package/dist/parsers/proto/index.js +197 -0
- package/dist/parsers/psd/index.d.ts +16 -0
- package/dist/parsers/psd/index.js +10 -0
- package/dist/parsers/shapefile/dbf.d.ts +23 -0
- package/dist/parsers/shapefile/dbf.js +112 -0
- package/dist/parsers/shapefile/index.d.ts +44 -0
- package/dist/parsers/shapefile/index.js +119 -0
- package/dist/parsers/shapefile/reproject.d.ts +10 -0
- package/dist/parsers/shapefile/reproject.js +41 -0
- package/dist/parsers/slide-model.d.ts +106 -0
- package/dist/parsers/slide-model.js +1 -0
- package/dist/parsers/toml/index.d.ts +15 -0
- package/dist/parsers/toml/index.js +18 -0
- package/dist/parsers/toml/model.d.ts +15 -0
- package/dist/parsers/toml/model.js +1 -0
- package/dist/parsers/toml/parse.d.ts +16 -0
- package/dist/parsers/toml/parse.js +266 -0
- package/dist/parsers/types.d.ts +103 -0
- package/dist/parsers/types.js +106 -0
- package/dist/parsers/video/index.d.ts +6 -0
- package/dist/parsers/video/index.js +2 -0
- package/dist/parsers/yaml/index.d.ts +16 -0
- package/dist/parsers/yaml/index.js +58 -0
- package/dist/parsers/yaml/model.d.ts +22 -0
- package/dist/parsers/yaml/model.js +1 -0
- package/dist/parsers/yaml/self-loading.d.ts +3 -0
- package/dist/parsers/yaml/self-loading.js +19 -0
- package/dist/parsers/zip-scan.d.ts +8 -0
- package/dist/parsers/zip-scan.js +80 -0
- package/dist/registry/container.d.ts +17 -0
- package/dist/registry/container.js +49 -0
- package/dist/registry/index.d.ts +133 -0
- package/dist/registry/index.js +348 -0
- package/dist/registry/probe.d.ts +3 -0
- package/dist/registry/probe.js +177 -0
- package/dist/registry/sniff.d.ts +17 -0
- package/dist/registry/sniff.js +57 -0
- package/dist/styles/archive.css +10 -0
- package/dist/styles/audio.css +66 -0
- package/dist/styles/automotive.css +1 -0
- package/dist/styles/csv.css +262 -0
- package/dist/styles/excel.css +212 -0
- package/dist/styles/fallback.css +48 -0
- package/dist/styles/hdf5.css +3 -0
- package/dist/styles/hwp.css +12 -0
- package/dist/styles/image.css +115 -0
- package/dist/styles/json.css +342 -0
- package/dist/styles/jsonl.css +1 -0
- package/dist/styles/markdown.css +10 -0
- package/dist/styles/mat.css +2 -0
- package/dist/styles/mermaid.css +1 -0
- package/dist/styles/parquet.css +2 -0
- package/dist/styles/pdf.css +551 -0
- package/dist/styles/plantuml.css +1 -0
- package/dist/styles/ppt.css +1 -0
- package/dist/styles/proto.css +2 -0
- package/dist/styles/psd.css +1 -0
- package/dist/styles/shapefile.css +25 -0
- package/dist/styles/toml.css +1 -0
- package/dist/styles/video.css +74 -0
- package/dist/styles/word.css +685 -0
- package/dist/styles/yaml.css +1 -0
- package/dist/viewers/a2l/index.d.ts +15 -0
- package/dist/viewers/a2l/index.js +5 -0
- package/dist/viewers/archive/archive-preview-decoder.d.ts +4 -0
- package/dist/viewers/archive/archive-preview-decoder.js +223 -0
- package/dist/viewers/archive/controller.d.ts +24 -0
- package/dist/viewers/archive/controller.js +18 -0
- package/dist/viewers/archive/index.d.ts +25 -0
- package/dist/viewers/archive/index.js +230 -0
- package/dist/viewers/archive/preview.d.ts +2 -0
- package/dist/viewers/archive/preview.js +2 -0
- package/dist/viewers/archive/styles.d.ts +1 -0
- package/dist/viewers/archive/styles.js +11 -0
- package/dist/viewers/arxml/index.d.ts +15 -0
- package/dist/viewers/arxml/index.js +5 -0
- package/dist/viewers/asc/index.d.ts +15 -0
- package/dist/viewers/asc/index.js +5 -0
- package/dist/viewers/audio/controller.d.ts +33 -0
- package/dist/viewers/audio/controller.js +49 -0
- package/dist/viewers/audio/engine.d.ts +44 -0
- package/dist/viewers/audio/engine.js +108 -0
- package/dist/viewers/audio/index.d.ts +92 -0
- package/dist/viewers/audio/index.js +448 -0
- package/dist/viewers/audio/self-loading.d.ts +7 -0
- package/dist/viewers/audio/self-loading.js +42 -0
- package/dist/viewers/audio/styles.d.ts +1 -0
- package/dist/viewers/audio/styles.js +73 -0
- package/dist/viewers/automotive/index.d.ts +8 -0
- package/dist/viewers/automotive/index.js +152 -0
- package/dist/viewers/automotive/styles.d.ts +1 -0
- package/dist/viewers/automotive/styles.js +1 -0
- package/dist/viewers/avro/index.d.ts +15 -0
- package/dist/viewers/avro/index.js +5 -0
- package/dist/viewers/bag/index.d.ts +15 -0
- package/dist/viewers/bag/index.js +5 -0
- package/dist/viewers/blf/index.d.ts +15 -0
- package/dist/viewers/blf/index.js +5 -0
- package/dist/viewers/csv/controller.d.ts +126 -0
- package/dist/viewers/csv/controller.js +598 -0
- package/dist/viewers/csv/index.d.ts +48 -0
- package/dist/viewers/csv/index.js +846 -0
- package/dist/viewers/csv/styles.d.ts +1 -0
- package/dist/viewers/csv/styles.js +267 -0
- package/dist/viewers/db3/index.d.ts +15 -0
- package/dist/viewers/db3/index.js +5 -0
- package/dist/viewers/dbc/index.d.ts +15 -0
- package/dist/viewers/dbc/index.js +5 -0
- package/dist/viewers/diagram.d.ts +14 -0
- package/dist/viewers/diagram.js +95 -0
- package/dist/viewers/excel/controller.d.ts +108 -0
- package/dist/viewers/excel/controller.js +548 -0
- package/dist/viewers/excel/grid.d.ts +28 -0
- package/dist/viewers/excel/grid.js +99 -0
- package/dist/viewers/excel/index.d.ts +37 -0
- package/dist/viewers/excel/index.js +620 -0
- package/dist/viewers/excel/self-loading.d.ts +6 -0
- package/dist/viewers/excel/self-loading.js +13 -0
- package/dist/viewers/excel/styles.d.ts +1 -0
- package/dist/viewers/excel/styles.js +216 -0
- package/dist/viewers/fallback/index.d.ts +17 -0
- package/dist/viewers/fallback/index.js +130 -0
- package/dist/viewers/fallback/styles.d.ts +1 -0
- package/dist/viewers/fallback/styles.js +49 -0
- package/dist/viewers/hdf5/index.d.ts +19 -0
- package/dist/viewers/hdf5/index.js +170 -0
- package/dist/viewers/hdf5/styles.d.ts +1 -0
- package/dist/viewers/hdf5/styles.js +4 -0
- package/dist/viewers/hwp/controller.d.ts +19 -0
- package/dist/viewers/hwp/controller.js +22 -0
- package/dist/viewers/hwp/index.d.ts +39 -0
- package/dist/viewers/hwp/index.js +271 -0
- package/dist/viewers/hwp/self-loading.d.ts +2 -0
- package/dist/viewers/hwp/self-loading.js +6 -0
- package/dist/viewers/hwp/styles.d.ts +1 -0
- package/dist/viewers/hwp/styles.js +13 -0
- package/dist/viewers/image/controller.d.ts +210 -0
- package/dist/viewers/image/controller.js +336 -0
- package/dist/viewers/image/decode.d.ts +54 -0
- package/dist/viewers/image/decode.js +150 -0
- package/dist/viewers/image/index.d.ts +38 -0
- package/dist/viewers/image/index.js +749 -0
- package/dist/viewers/image/limits.d.ts +18 -0
- package/dist/viewers/image/limits.js +20 -0
- package/dist/viewers/image/styles.d.ts +1 -0
- package/dist/viewers/image/styles.js +119 -0
- package/dist/viewers/json/controller.d.ts +89 -0
- package/dist/viewers/json/controller.js +411 -0
- package/dist/viewers/json/index.d.ts +25 -0
- package/dist/viewers/json/index.js +503 -0
- package/dist/viewers/json/styles.d.ts +1 -0
- package/dist/viewers/json/styles.js +346 -0
- package/dist/viewers/json/transforms.d.ts +27 -0
- package/dist/viewers/json/transforms.js +253 -0
- package/dist/viewers/jsonl/controller.d.ts +48 -0
- package/dist/viewers/jsonl/controller.js +136 -0
- package/dist/viewers/jsonl/index.d.ts +22 -0
- package/dist/viewers/jsonl/index.js +184 -0
- package/dist/viewers/jsonl/styles.d.ts +1 -0
- package/dist/viewers/jsonl/styles.js +1 -0
- package/dist/viewers/markdown/controller.d.ts +50 -0
- package/dist/viewers/markdown/controller.js +62 -0
- package/dist/viewers/markdown/index.d.ts +64 -0
- package/dist/viewers/markdown/index.js +425 -0
- package/dist/viewers/markdown/math.d.ts +21 -0
- package/dist/viewers/markdown/math.js +100 -0
- package/dist/viewers/markdown/self-loading.d.ts +5 -0
- package/dist/viewers/markdown/self-loading.js +48 -0
- package/dist/viewers/markdown/styles.d.ts +1 -0
- package/dist/viewers/markdown/styles.js +11 -0
- package/dist/viewers/mat/index.d.ts +19 -0
- package/dist/viewers/mat/index.js +113 -0
- package/dist/viewers/mat/styles.d.ts +1 -0
- package/dist/viewers/mat/styles.js +3 -0
- package/dist/viewers/media.d.ts +9 -0
- package/dist/viewers/media.js +77 -0
- package/dist/viewers/mermaid/index.d.ts +17 -0
- package/dist/viewers/mermaid/index.js +6 -0
- package/dist/viewers/mermaid/self-loading.d.ts +2 -0
- package/dist/viewers/mermaid/self-loading.js +2 -0
- package/dist/viewers/mf4/index.d.ts +15 -0
- package/dist/viewers/mf4/index.js +5 -0
- package/dist/viewers/parquet/controller.d.ts +37 -0
- package/dist/viewers/parquet/controller.js +26 -0
- package/dist/viewers/parquet/index.d.ts +23 -0
- package/dist/viewers/parquet/index.js +134 -0
- package/dist/viewers/parquet/styles.d.ts +1 -0
- package/dist/viewers/parquet/styles.js +3 -0
- package/dist/viewers/pcap/index.d.ts +15 -0
- package/dist/viewers/pcap/index.js +5 -0
- package/dist/viewers/pcapng/index.d.ts +15 -0
- package/dist/viewers/pcapng/index.js +5 -0
- package/dist/viewers/pdf/controller.d.ts +120 -0
- package/dist/viewers/pdf/controller.js +191 -0
- package/dist/viewers/pdf/editing.d.ts +26 -0
- package/dist/viewers/pdf/editing.js +265 -0
- package/dist/viewers/pdf/index.d.ts +88 -0
- package/dist/viewers/pdf/index.js +1400 -0
- package/dist/viewers/pdf/self-loading.d.ts +6 -0
- package/dist/viewers/pdf/self-loading.js +14 -0
- package/dist/viewers/pdf/styles.d.ts +1 -0
- package/dist/viewers/pdf/styles.js +555 -0
- package/dist/viewers/plantuml/index.d.ts +17 -0
- package/dist/viewers/plantuml/index.js +6 -0
- package/dist/viewers/plantuml/self-loading.d.ts +2 -0
- package/dist/viewers/plantuml/self-loading.js +2 -0
- package/dist/viewers/ppt/chart.d.ts +8 -0
- package/dist/viewers/ppt/chart.js +83 -0
- package/dist/viewers/ppt/controller.d.ts +34 -0
- package/dist/viewers/ppt/controller.js +27 -0
- package/dist/viewers/ppt/index.d.ts +33 -0
- package/dist/viewers/ppt/index.js +101 -0
- package/dist/viewers/ppt/render.d.ts +5 -0
- package/dist/viewers/ppt/render.js +144 -0
- package/dist/viewers/ppt/self-loading.d.ts +9 -0
- package/dist/viewers/ppt/self-loading.js +4 -0
- package/dist/viewers/ppt/styles.d.ts +1 -0
- package/dist/viewers/ppt/styles.js +1 -0
- package/dist/viewers/proto/index.d.ts +17 -0
- package/dist/viewers/proto/index.js +170 -0
- package/dist/viewers/proto/styles.d.ts +1 -0
- package/dist/viewers/proto/styles.js +2 -0
- package/dist/viewers/psd/index.d.ts +27 -0
- package/dist/viewers/psd/index.js +39 -0
- package/dist/viewers/psd/self-loading.d.ts +10 -0
- package/dist/viewers/psd/self-loading.js +20 -0
- package/dist/viewers/psd/styles.d.ts +1 -0
- package/dist/viewers/psd/styles.js +1 -0
- package/dist/viewers/reqif/index.d.ts +15 -0
- package/dist/viewers/reqif/index.js +5 -0
- package/dist/viewers/shapefile/index.d.ts +35 -0
- package/dist/viewers/shapefile/index.js +336 -0
- package/dist/viewers/shapefile/self-loading.d.ts +7 -0
- package/dist/viewers/shapefile/self-loading.js +32 -0
- package/dist/viewers/shapefile/styles.d.ts +1 -0
- package/dist/viewers/shapefile/styles.js +28 -0
- package/dist/viewers/stp/index.d.ts +15 -0
- package/dist/viewers/stp/index.js +5 -0
- package/dist/viewers/structured-styles.d.ts +1 -0
- package/dist/viewers/structured-styles.js +1 -0
- package/dist/viewers/structured.d.ts +36 -0
- package/dist/viewers/structured.js +138 -0
- package/dist/viewers/toml/controller.d.ts +38 -0
- package/dist/viewers/toml/controller.js +61 -0
- package/dist/viewers/toml/index.d.ts +18 -0
- package/dist/viewers/toml/index.js +34 -0
- package/dist/viewers/types.d.ts +36 -0
- package/dist/viewers/types.js +9 -0
- package/dist/viewers/video/controller.d.ts +29 -0
- package/dist/viewers/video/controller.js +54 -0
- package/dist/viewers/video/index.d.ts +18 -0
- package/dist/viewers/video/index.js +305 -0
- package/dist/viewers/video/styles.d.ts +1 -0
- package/dist/viewers/video/styles.js +79 -0
- package/dist/viewers/word/controller.d.ts +19 -0
- package/dist/viewers/word/controller.js +22 -0
- package/dist/viewers/word/docx-preprocess.d.ts +63 -0
- package/dist/viewers/word/docx-preprocess.js +136 -0
- package/dist/viewers/word/index.d.ts +32 -0
- package/dist/viewers/word/index.js +187 -0
- package/dist/viewers/word/normalize-docx.d.ts +2 -0
- package/dist/viewers/word/normalize-docx.js +50 -0
- package/dist/viewers/word/paginate.d.ts +1 -0
- package/dist/viewers/word/paginate.js +1035 -0
- package/dist/viewers/word/self-loading.d.ts +2 -0
- package/dist/viewers/word/self-loading.js +7 -0
- package/dist/viewers/word/styles.d.ts +1 -0
- package/dist/viewers/word/styles.js +686 -0
- package/dist/viewers/yaml/controller.d.ts +42 -0
- package/dist/viewers/yaml/controller.js +41 -0
- package/dist/viewers/yaml/index.d.ts +21 -0
- package/dist/viewers/yaml/index.js +20 -0
- package/package.json +375 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { Hdf5Parser, formatFileSize } from './index.js';
|
|
3
|
+
const EMPTY = new Uint8Array(0);
|
|
4
|
+
/**
|
|
5
|
+
* File-descriptor-backed random-access reader for Node hosts such as VS Code.
|
|
6
|
+
* A 4 MiB LRU page cache keeps metadata traversal cheap without loading HDF5
|
|
7
|
+
* dataset payloads or the complete file into memory.
|
|
8
|
+
*/
|
|
9
|
+
export class Hdf5FileReader {
|
|
10
|
+
fd;
|
|
11
|
+
size;
|
|
12
|
+
static PAGE_BYTES = 64 * 1024;
|
|
13
|
+
static MAX_PAGES = 64;
|
|
14
|
+
cache = new Map();
|
|
15
|
+
closed = false;
|
|
16
|
+
constructor(fd, size) {
|
|
17
|
+
this.fd = fd;
|
|
18
|
+
this.size = size;
|
|
19
|
+
}
|
|
20
|
+
static open(filePath) {
|
|
21
|
+
const fd = fs.openSync(filePath, 'r');
|
|
22
|
+
try {
|
|
23
|
+
return new Hdf5FileReader(fd, fs.fstatSync(fd).size);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
fs.closeSync(fd);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
read(offset, length) {
|
|
31
|
+
if (this.closed)
|
|
32
|
+
throw new Error('HDF5 reader is closed');
|
|
33
|
+
const start = Math.max(0, offset);
|
|
34
|
+
const end = Math.min(offset + length, this.size);
|
|
35
|
+
if (end <= start)
|
|
36
|
+
return EMPTY;
|
|
37
|
+
const out = new Uint8Array(end - start);
|
|
38
|
+
let position = start;
|
|
39
|
+
while (position < end) {
|
|
40
|
+
const pageIndex = Math.floor(position / Hdf5FileReader.PAGE_BYTES);
|
|
41
|
+
const page = this.getPage(pageIndex);
|
|
42
|
+
const inPage = position - pageIndex * Hdf5FileReader.PAGE_BYTES;
|
|
43
|
+
const copyLength = Math.min(page.byteLength - inPage, end - position);
|
|
44
|
+
if (copyLength <= 0)
|
|
45
|
+
break;
|
|
46
|
+
out.set(page.subarray(inPage, inPage + copyLength), position - start);
|
|
47
|
+
position += copyLength;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
close() {
|
|
52
|
+
if (this.closed)
|
|
53
|
+
return;
|
|
54
|
+
this.closed = true;
|
|
55
|
+
this.cache.clear();
|
|
56
|
+
try {
|
|
57
|
+
fs.closeSync(this.fd);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Closing is best-effort and must not mask a parser failure.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getPage(pageIndex) {
|
|
64
|
+
const cached = this.cache.get(pageIndex);
|
|
65
|
+
if (cached) {
|
|
66
|
+
this.cache.delete(pageIndex);
|
|
67
|
+
this.cache.set(pageIndex, cached);
|
|
68
|
+
return cached;
|
|
69
|
+
}
|
|
70
|
+
const start = pageIndex * Hdf5FileReader.PAGE_BYTES;
|
|
71
|
+
const length = Math.min(Hdf5FileReader.PAGE_BYTES, this.size - start);
|
|
72
|
+
if (length <= 0)
|
|
73
|
+
return EMPTY;
|
|
74
|
+
const page = new Uint8Array(length);
|
|
75
|
+
const bytesRead = fs.readSync(this.fd, page, 0, length, start);
|
|
76
|
+
const value = bytesRead === length ? page : page.subarray(0, bytesRead);
|
|
77
|
+
if (this.cache.size >= Hdf5FileReader.MAX_PAGES) {
|
|
78
|
+
const oldest = this.cache.keys().next().value;
|
|
79
|
+
if (oldest !== undefined)
|
|
80
|
+
this.cache.delete(oldest);
|
|
81
|
+
}
|
|
82
|
+
this.cache.set(pageIndex, value);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Parse an HDF5 file without loading dataset payloads into memory. */
|
|
87
|
+
export function parseHdf5File(filePath, fileSize) {
|
|
88
|
+
const reader = Hdf5FileReader.open(filePath);
|
|
89
|
+
try {
|
|
90
|
+
return Hdf5Parser.parseReader(reader, fileSize ?? formatFileSize(reader.size));
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
reader.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParseOptions, ParseOutcome } from '../types.js';
|
|
2
|
+
import type { JsonDocument } from './model.js';
|
|
3
|
+
export type { JsonDocument, JsonNode, JsonValueKind } from './model.js';
|
|
4
|
+
export { appendPath, decodeJsonString, encodeJsonString } from './model.js';
|
|
5
|
+
export { tokenizeJson } from './tokenizer.js';
|
|
6
|
+
export type { JsonToken, JsonTokenKind } from './tokenizer.js';
|
|
7
|
+
export { parseJsonDocument, JSON_DEFAULT_MAX_DEPTH } from './parse.js';
|
|
8
|
+
export type { JsonParseTree, ParseTreeOptions } from './parse.js';
|
|
9
|
+
export interface JsonParseOptions extends ParseOptions {
|
|
10
|
+
/** Nesting depth cap (default JSON_DEFAULT_MAX_DEPTH) — deep-nesting defense. */
|
|
11
|
+
maxDepth?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Input ownership: borrows the input; the caller keeps the bytes (DESIGN §3-①). */
|
|
14
|
+
export declare const JSON_INPUT_OWNERSHIP: "borrows";
|
|
15
|
+
export declare function parseJson(input: Uint8Array | string, options?: JsonParseOptions): ParseOutcome<JsonDocument>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// JSON parser entry — the core contract surface (DESIGN.md §3-①, J1 = 원문
|
|
2
|
+
// 보존 토크나이저). parseJson(bytes or text) -> ParseOutcome<JsonDocument>.
|
|
3
|
+
// Input-caused failures never throw; limits stop with `partial` + a diagnostic;
|
|
4
|
+
// a syntax error yields the recovered prefix as `partial` (or `failed` if
|
|
5
|
+
// nothing parsed) while the source text stays available for the verbatim view.
|
|
6
|
+
import { DEFAULT_LIMITS, LimitTracker, decodeUtf8, utf8ByteLength } from '../types.js';
|
|
7
|
+
import { JSON_DEFAULT_MAX_DEPTH, parseJsonDocument } from './parse.js';
|
|
8
|
+
export { appendPath, decodeJsonString, encodeJsonString } from './model.js';
|
|
9
|
+
export { tokenizeJson } from './tokenizer.js';
|
|
10
|
+
export { parseJsonDocument, JSON_DEFAULT_MAX_DEPTH } from './parse.js';
|
|
11
|
+
/** Input ownership: borrows the input; the caller keeps the bytes (DESIGN §3-①). */
|
|
12
|
+
export const JSON_INPUT_OWNERSHIP = 'borrows';
|
|
13
|
+
/** How often (in nodes) the cooperative abort/time checkpoint runs. */
|
|
14
|
+
const CHECKPOINT_INTERVAL = 256;
|
|
15
|
+
export function parseJson(input, options = {}) {
|
|
16
|
+
const started = Date.now();
|
|
17
|
+
const limits = { ...DEFAULT_LIMITS, ...options.limits };
|
|
18
|
+
const diagnostics = [];
|
|
19
|
+
const finish = (result) => ({
|
|
20
|
+
result,
|
|
21
|
+
execution: {
|
|
22
|
+
workerUsed: false,
|
|
23
|
+
hardLimitEnforced: false,
|
|
24
|
+
elapsedMillis: Date.now() - started
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const inputBytes = typeof input === 'string' ? utf8ByteLength(input) : input.byteLength;
|
|
28
|
+
if (inputBytes > limits.maxInputBytes) {
|
|
29
|
+
return finish({
|
|
30
|
+
status: 'failed',
|
|
31
|
+
failure: {
|
|
32
|
+
code: 'limit-exceeded',
|
|
33
|
+
retryable: false,
|
|
34
|
+
messageKey: 'diag.limit-exceeded.input',
|
|
35
|
+
args: { maxBytes: limits.maxInputBytes }
|
|
36
|
+
},
|
|
37
|
+
diagnostics
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (options.signal?.aborted) {
|
|
41
|
+
return finish({
|
|
42
|
+
status: 'failed',
|
|
43
|
+
failure: { code: 'aborted', retryable: true, messageKey: 'diag.aborted' },
|
|
44
|
+
diagnostics
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const text = typeof input === 'string' ? input : decodeUtf8(input);
|
|
48
|
+
const tracker = new LimitTracker(limits, options.signal);
|
|
49
|
+
const onNode = () => {
|
|
50
|
+
tracker.addEntries(1);
|
|
51
|
+
const count = tracker.entryCount;
|
|
52
|
+
// Amortize the abort/time checks; always enforce the node cap.
|
|
53
|
+
if (count % CHECKPOINT_INTERVAL !== 0 && count <= limits.maxEntries) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const violation = tracker.checkpoint();
|
|
57
|
+
if (!violation)
|
|
58
|
+
return null;
|
|
59
|
+
return violation.kind === 'aborted' ? 'abort' : 'limit';
|
|
60
|
+
};
|
|
61
|
+
const tree = parseJsonDocument(text, {
|
|
62
|
+
maxDepth: options.maxDepth ?? JSON_DEFAULT_MAX_DEPTH,
|
|
63
|
+
onNode
|
|
64
|
+
});
|
|
65
|
+
diagnostics.push(...tree.diagnostics);
|
|
66
|
+
// Cancellation is a failure regardless of how much parsed (parity with csv).
|
|
67
|
+
if (tree.stopped && tree.stopReason === 'abort') {
|
|
68
|
+
return finish({
|
|
69
|
+
status: 'failed',
|
|
70
|
+
failure: { code: 'aborted', retryable: true, messageKey: 'diag.aborted' },
|
|
71
|
+
diagnostics
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Nothing recovered — the verbatim view falls back to the raw bytes (J20),
|
|
75
|
+
// so the viewer still shows the source; the model result is `failed`.
|
|
76
|
+
if (!tree.root) {
|
|
77
|
+
return finish({
|
|
78
|
+
status: 'failed',
|
|
79
|
+
failure: {
|
|
80
|
+
code: 'invalid-format',
|
|
81
|
+
retryable: false,
|
|
82
|
+
messageKey: 'diag.json.invalid'
|
|
83
|
+
},
|
|
84
|
+
diagnostics
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const document = { root: tree.root, text };
|
|
88
|
+
if (tree.stopped && tree.stopReason === 'limit') {
|
|
89
|
+
diagnostics.push({
|
|
90
|
+
severity: 'warning',
|
|
91
|
+
code: 'limit-exceeded',
|
|
92
|
+
messageKey: 'diag.limit-exceeded.nodes',
|
|
93
|
+
args: { count: tracker.entryCount }
|
|
94
|
+
});
|
|
95
|
+
return finish({ status: 'partial', document, diagnostics });
|
|
96
|
+
}
|
|
97
|
+
// A syntax error or trailing content means we recovered only a prefix.
|
|
98
|
+
if (tree.errored || tree.trailing) {
|
|
99
|
+
return finish({ status: 'partial', document, diagnostics });
|
|
100
|
+
}
|
|
101
|
+
return finish({ status: 'ok', document, diagnostics });
|
|
102
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type JsonValueKind = 'object' | 'array' | 'string' | 'number' | 'boolean' | 'null';
|
|
2
|
+
export interface JsonNode {
|
|
3
|
+
kind: JsonValueKind;
|
|
4
|
+
/** Key within the parent object, array index as a string, or '$' for root. */
|
|
5
|
+
key: string;
|
|
6
|
+
/** JSONPath from the root, e.g. '$.a.b[0]' or '$["odd key"]'. */
|
|
7
|
+
path: string;
|
|
8
|
+
depth: number;
|
|
9
|
+
/** object/array only — ordered children; duplicate object keys are kept. */
|
|
10
|
+
children?: JsonNode[];
|
|
11
|
+
/** primitive value: decoded string, boolean, or null. Numbers use rawNumber. */
|
|
12
|
+
value?: string | boolean | null;
|
|
13
|
+
/** number only — the verbatim token (e.g. "1e400", big ints), no rounding. */
|
|
14
|
+
rawNumber?: string;
|
|
15
|
+
/** [start, end) char range in the source text (verbatim slice / error locus). */
|
|
16
|
+
span: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface JsonDocument {
|
|
22
|
+
root: JsonNode;
|
|
23
|
+
/** Decoded source text; also lets a failed parse still show the source (J20). */
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build a child JSONPath (parity with web JsonViewer.appendPath): identifier
|
|
28
|
+
* keys use dot notation, everything else uses bracket-quoted notation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function appendPath(parent: string, key: string, isArrayItem: boolean): string;
|
|
31
|
+
/**
|
|
32
|
+
* Encode a string as a JSON string literal (with surrounding quotes),
|
|
33
|
+
* deterministically and without JSON.stringify (ADR 41). Used for bracket
|
|
34
|
+
* path keys and, later, re-serialization.
|
|
35
|
+
*/
|
|
36
|
+
export declare function encodeJsonString(value: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Decode a JSON string literal (including its surrounding quotes) to its text
|
|
39
|
+
* value. Deterministic, never throws — malformed escapes fall back to the
|
|
40
|
+
* literal characters so a recovered/partial parse still yields a usable value.
|
|
41
|
+
*/
|
|
42
|
+
export declare function decodeJsonString(raw: string): string;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// JSON document model (docs/parsers/json.md, J1 = 원문 보존 토크나이저).
|
|
2
|
+
//
|
|
3
|
+
// Preserves the fidelity JSON.parse loses: raw number text (no float64
|
|
4
|
+
// rounding), duplicate object keys (kept in order), and source char spans so
|
|
5
|
+
// the verbatim source view and error loci can slice the original text.
|
|
6
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
7
|
+
/**
|
|
8
|
+
* Build a child JSONPath (parity with web JsonViewer.appendPath): identifier
|
|
9
|
+
* keys use dot notation, everything else uses bracket-quoted notation.
|
|
10
|
+
*/
|
|
11
|
+
export function appendPath(parent, key, isArrayItem) {
|
|
12
|
+
if (isArrayItem)
|
|
13
|
+
return `${parent}[${key}]`;
|
|
14
|
+
return IDENTIFIER.test(key)
|
|
15
|
+
? `${parent}.${key}`
|
|
16
|
+
: `${parent}[${encodeJsonString(key)}]`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Encode a string as a JSON string literal (with surrounding quotes),
|
|
20
|
+
* deterministically and without JSON.stringify (ADR 41). Used for bracket
|
|
21
|
+
* path keys and, later, re-serialization.
|
|
22
|
+
*/
|
|
23
|
+
export function encodeJsonString(value) {
|
|
24
|
+
let out = '"';
|
|
25
|
+
for (let i = 0; i < value.length; i++) {
|
|
26
|
+
const ch = value.charCodeAt(i);
|
|
27
|
+
switch (ch) {
|
|
28
|
+
case 0x22:
|
|
29
|
+
out += '\\"';
|
|
30
|
+
break;
|
|
31
|
+
case 0x5c:
|
|
32
|
+
out += '\\\\';
|
|
33
|
+
break;
|
|
34
|
+
case 0x08:
|
|
35
|
+
out += '\\b';
|
|
36
|
+
break;
|
|
37
|
+
case 0x0c:
|
|
38
|
+
out += '\\f';
|
|
39
|
+
break;
|
|
40
|
+
case 0x0a:
|
|
41
|
+
out += '\\n';
|
|
42
|
+
break;
|
|
43
|
+
case 0x0d:
|
|
44
|
+
out += '\\r';
|
|
45
|
+
break;
|
|
46
|
+
case 0x09:
|
|
47
|
+
out += '\\t';
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
if (ch < 0x20) {
|
|
51
|
+
out += '\\u' + ch.toString(16).padStart(4, '0');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
out += value[i];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out + '"';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Decode a JSON string literal (including its surrounding quotes) to its text
|
|
62
|
+
* value. Deterministic, never throws — malformed escapes fall back to the
|
|
63
|
+
* literal characters so a recovered/partial parse still yields a usable value.
|
|
64
|
+
*/
|
|
65
|
+
export function decodeJsonString(raw) {
|
|
66
|
+
// Strip surrounding quotes if present (the scanner may hand us an
|
|
67
|
+
// unterminated literal on recovery).
|
|
68
|
+
let start = 0;
|
|
69
|
+
let end = raw.length;
|
|
70
|
+
if (raw.charCodeAt(0) === 0x22)
|
|
71
|
+
start = 1;
|
|
72
|
+
if (end > start && raw.charCodeAt(end - 1) === 0x22)
|
|
73
|
+
end -= 1;
|
|
74
|
+
let out = '';
|
|
75
|
+
let i = start;
|
|
76
|
+
while (i < end) {
|
|
77
|
+
const ch = raw.charCodeAt(i);
|
|
78
|
+
if (ch !== 0x5c /* \ */) {
|
|
79
|
+
out += raw[i];
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const next = raw[i + 1];
|
|
84
|
+
if (next === undefined) {
|
|
85
|
+
out += '\\';
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
switch (next) {
|
|
89
|
+
case '"':
|
|
90
|
+
out += '"';
|
|
91
|
+
i += 2;
|
|
92
|
+
break;
|
|
93
|
+
case '\\':
|
|
94
|
+
out += '\\';
|
|
95
|
+
i += 2;
|
|
96
|
+
break;
|
|
97
|
+
case '/':
|
|
98
|
+
out += '/';
|
|
99
|
+
i += 2;
|
|
100
|
+
break;
|
|
101
|
+
case 'b':
|
|
102
|
+
out += '\b';
|
|
103
|
+
i += 2;
|
|
104
|
+
break;
|
|
105
|
+
case 'f':
|
|
106
|
+
out += '\f';
|
|
107
|
+
i += 2;
|
|
108
|
+
break;
|
|
109
|
+
case 'n':
|
|
110
|
+
out += '\n';
|
|
111
|
+
i += 2;
|
|
112
|
+
break;
|
|
113
|
+
case 'r':
|
|
114
|
+
out += '\r';
|
|
115
|
+
i += 2;
|
|
116
|
+
break;
|
|
117
|
+
case 't':
|
|
118
|
+
out += '\t';
|
|
119
|
+
i += 2;
|
|
120
|
+
break;
|
|
121
|
+
case 'u': {
|
|
122
|
+
const hex = raw.slice(i + 2, i + 6);
|
|
123
|
+
if (/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
124
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
125
|
+
i += 6;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
out += '\\u';
|
|
129
|
+
i += 2;
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
// Unknown escape — keep it literal (lossless for recovery).
|
|
135
|
+
out += next;
|
|
136
|
+
i += 2;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Diagnostic } from '../types.js';
|
|
2
|
+
import { type JsonNode } from './model.js';
|
|
3
|
+
/** Reason a checkpoint asked the parser to stop. */
|
|
4
|
+
export type StopReason = 'abort' | 'limit';
|
|
5
|
+
export interface ParseTreeOptions {
|
|
6
|
+
maxDepth?: number;
|
|
7
|
+
/** Called once per node; return a stop reason to halt, or null to continue. */
|
|
8
|
+
onNode?: () => StopReason | null;
|
|
9
|
+
}
|
|
10
|
+
export interface JsonParseTree {
|
|
11
|
+
root: JsonNode | null;
|
|
12
|
+
diagnostics: Diagnostic[];
|
|
13
|
+
/** A checkpoint (abort/limit) halted parsing. */
|
|
14
|
+
stopped: boolean;
|
|
15
|
+
stopReason: StopReason | null;
|
|
16
|
+
/** A syntax error prevented a complete parse. */
|
|
17
|
+
errored: boolean;
|
|
18
|
+
/** Non-whitespace content followed the top-level value. */
|
|
19
|
+
trailing: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const JSON_DEFAULT_MAX_DEPTH = 500;
|
|
22
|
+
export declare function parseJsonDocument(text: string, options?: ParseTreeOptions): JsonParseTree;
|