Public
Edited
Feb 27, 2024
Insert cell
Insert cell
data = (await FileAttachment("test2.qrcbin")).arrayBuffer()
Insert cell
Insert cell
root_entries = parse_tree(data).root.children
Insert cell
Insert cell
parsed_files = get_files(
{ names_start_offset: 0xdc, payload_start_offset: 0x16c },
root_entries
)
Insert cell
Insert cell
function get_name(offset) {
return parse_name(data.slice(offset)).nodeName.name;
}
Insert cell
function get_files(
{ names_start_offset, payload_start_offset },
entries,
path = ":/"
) {
let r = [];
for (const e of entries) {
const p =
path +
get_name(names_start_offset + e.nameOffset) +
(e.directory ? "/" : "");

if (e.directory) {
r = r.concat(
get_files({ names_start_offset, payload_start_offset }, e.children, p)
);
} else {
const last_modified = new Date(e.lastModified);

const view = new DataView(data);
const data_start = payload_start_offset + e.dataOffset;
const size = view.getInt32(data_start, false); // false for big-endian
const arr = data.slice(data_start + 4, data_start + 4 + size);

r.push({
name: p,
last_modified,
data: new Uint8Array(arr)
});
}
}
return r;
}
Insert cell
Insert cell
Insert cell
Insert cell
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