Public
Edited
Nov 26, 2023
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
parse = function(arrayBuffer) {
return new parser(new KaitaiStream(arrayBuffer))
}
Insert cell
process_generators = []
Insert cell
function patch_parser_evaluatable(evaluatable) {
return evaluatable;
}
Insert cell
Insert cell
parsed_ksy = yaml.parse(ksy)
Insert cell
parser_sources = KaitaiStructCompiler.compile(
'javascript',
parsed_ksy,
null,
false
)
Insert cell
parser_source = parser_sources[Object.keys(parser_sources)[0]]
Insert cell
// Leave only just enough code to make it evaluatable.
parser_evaluatable = parser_source.replace(
// 0.9.0
// /[\w\W]+(\(this\, function \(KaitaiStream[\w\W]+)\)\;/,
// latest
/[\w\W]+(\((?:typeof self \!\=\= 'undefined' \? self \: )?this\, function \(KaitaiStream[\w\W]+)\)\;/,
"$1"
)
Insert cell
parser = eval(patch_parser_evaluatable(parser_evaluatable))(
KaitaiStream,
...process_generators
)
Insert cell
Insert cell
// constructor(inputBuffer: ArrayBufferLike, offset: number);
KaitaiStream = require('kaitai-struct/KaitaiStream.js')
Insert cell
// https://github.com/kaitai-io/kaitai_struct_webide/blob/b5fadb8fe7b57c63547f9a0a052b0c0634e396f6/lib/ts-types/kaitai.d.ts
// compile(kslang: string, compilerSchema: any, jsImporter: IYamlImporter, isDebug: boolean): Promise<{ [filename: string]: string }>;
KaitaiStructCompiler = (await require("kaitai-struct-compiler@latest"))()

// 0.9.0 was working fine
Insert cell
// yaml = require('https://bundle.run/yamljs@0.3.0')
yaml = require(await FileAttachment("yamljs-0.3.0.js").url())
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more