Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from "fs";
- import util from "util";
- const readFile = util.promisify(fs.readFile);
- const writer = process.stdout;
- (async function generateMarkdownBinaryTable() {
- const buffer = await readFile("chunk.txt");
- const data = buffer.toString();
- const blocks = data.trim().split("---");
- for (let block of blocks) {
- const lines = block.trim().split("\n");
- let offset = 0;
- writer.write(`| Offset | Size | Type | Field | Description |\n`);
- writer.write(`|--------|------|------|-------|-------------|\n`);
- for (let line of lines) {
- const segments = line.split(";");
- let [enableOffset, expression, type, description] = segments;
- const rowOffset = enableOffset === "0" ? "dynamic" : "0x" + offset.toString(16).padStart(5, "0");
- const byteSize = eval(expression);
- type = type ? type.trim() : "";
- description = description ? description.trim() : "";
- writer.write(`|${rowOffset}|${byteSize}|${type}|${description}|\n`);
- offset += parseInt(byteSize);
- }
- writer.write(`\n`);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement