Closed manzt closed 2 years ago
Since we merge context.ts into binary_parser.ts, the source code itself runs in deno :) Thanks for moving forward with these PRs. This library is very portable!
context.ts
binary_parser.ts
deno run --allow-net --no-check mod.ts
// mod.ts import { Parser } from 'https://raw.githubusercontent.com/keichi/binary-parser/master/lib/binary_parser.ts'; const oct2int = function (s) { return parseInt(s, 8); }; const tarHeader = new Parser() .string("name", { length: 100, stripNull: true }) .string("mode", { length: 8, stripNull: true, formatter: oct2int }) .string("uid", { length: 8, stripNull: true, formatter: oct2int }) .string("gid", { length: 8, stripNull: true, formatter: oct2int }) .string("size", { length: 12, stripNull: true, formatter: oct2int }) .string("mtime", { length: 12, stripNull: true, formatter: oct2int }) .string("chksum", { length: 8, stripNull: true, formatter: oct2int }) .string("typeflag", { length: 1, stripNull: true, formatter: oct2int }) .string("linkname", { length: 100, stripNull: true }) .string("magic", { length: 6, stripNull: true }) .string("version", { length: 2, stripNull: true, formatter: oct2int }) .string("uname", { length: 32, stripNull: true }) .string("gname", { length: 32, stripNull: true }) .string("devmajor", { length: 8, stripNull: true, formatter: oct2int }) .string("devminor", { length: 8, stripNull: true, formatter: oct2int }) .string("prefix", { length: 155, stripNull: true }) .seek(12); const tarItem = new Parser() .nest({ type: tarHeader, }) .seek(function () { return Math.ceil(this.size / 512) * 512; }); const tarArchive = new Parser().array("files", { type: tarItem, readUntil: "eof", }); fetch('https://github.com/keichi/binary-parser/raw/master/example/test.tar') .then(res => res.arrayBuffer()) .then(buf => tarArchive.parse(new Uint8Array(buf))) .then(console.log);
Feel free to close, but I thought I'd share.
Nice! We should have unit tests to officially support Deno and web browsers.
We also need to fix type-related errors to make it work without the --no-check flag.
--no-check
Since we merge
context.ts
intobinary_parser.ts
, the source code itself runs in deno :) Thanks for moving forward with these PRs. This library is very portable!Feel free to close, but I thought I'd share.