Published
Edited
Jan 9, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("40bd3c12-c559-4f0e-b22e-500be96ff530.rm")
Insert cell
Insert cell
parse = function(arrayBuffer) {
return new parser(new KaitaiStream(arrayBuffer))
}
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(
/[\w\W]+(\(this\, function \(KaitaiStream\)[\w\W]+)\)\;/,
'$1'
)
Insert cell
parser = eval(parser_evaluatable)(KaitaiStream)
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@0.9.0'))()
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