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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more