Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/bmp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from "fs";
import { join } from "path";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

// C structure BITMAPFILEHEADER
// typedef struct tagBITMAPFILEHEADER {
Expand Down Expand Up @@ -58,6 +58,6 @@ const bmpFile = new Parser()
type: bmpInfoHeader,
});

readFile(join(__dirname, "test.bmp"), (_, data) => {
readFile(join(import.meta.dirname, "test.bmp"), (_, data) => {
console.log(bmpFile.parse(data));
});
4 changes: 2 additions & 2 deletions example/classfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "fs";
import { join } from "path";
import { inspect } from "util";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const ConstantClassInfo = Parser.start().uint16be("name_index");

Expand Down Expand Up @@ -1307,6 +1307,6 @@ const ClassFile = Parser.start()
length: "attributes_count",
});

readFile(join(__dirname, "Hello.class"), (_, data) => {
readFile(join(import.meta.dirname, "Hello.class"), (_, data) => {
console.log(inspect(ClassFile.parse(data), { depth: null, colors: true }));
});
4 changes: 2 additions & 2 deletions example/elf32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "fs";
import { join } from "path";
import { inspect } from "util";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const ELF32ProgramHeader = new Parser()
.endianness("little")
Expand Down Expand Up @@ -82,7 +82,7 @@ const ELF32Header = new Parser()
},
});

readFile(join(__dirname, "hello"), (_, data) => {
readFile(join(import.meta.dirname, "hello"), (_, data) => {
const result = ELF32Header.parse(data);
console.log(inspect(result, { depth: null, colors: true }));
});
2 changes: 1 addition & 1 deletion example/ip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const ipHeader = new Parser()
.endianness("big")
Expand Down
4 changes: 2 additions & 2 deletions example/jpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "fs";
import { join } from "path";
import { inspect } from "util";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const SOI = Parser.start();

Expand Down Expand Up @@ -108,6 +108,6 @@ const JPEG = Parser.start().array("segments", {
readUntil: "eof",
});

readFile(join(__dirname, "test.jpg"), (_, data) => {
readFile(join(import.meta.dirname, "test.jpg"), (_, data) => {
console.log(inspect(JPEG.parse(data), { depth: null, colors: true }));
});
4 changes: 2 additions & 2 deletions example/mbr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "fs";
import { join } from "path";
import { inspect } from "util";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const chs = new Parser()
.uint8("head")
Expand Down Expand Up @@ -41,6 +41,6 @@ const mbrParser = new Parser()
assert: 0x55aa,
});

readFile(join(__dirname, "raspbian.img"), (_, data) => {
readFile(join(import.meta.dirname, "raspbian.img"), (_, data) => {
console.log(inspect(mbrParser.parse(data), { depth: null, colors: true }));
});
4 changes: 2 additions & 2 deletions example/tar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from "path";
import { readFile } from "fs";

import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

function oct2int(s: string): number {
return parseInt(s, 8);
Expand Down Expand Up @@ -39,6 +39,6 @@ const tarArchive = new Parser().array("files", {
readUntil: "eof",
});

readFile(join(__dirname, "test.tar"), (_, data) => {
readFile(join(import.meta.dirname, "test.tar"), (_, data) => {
console.dir(tarArchive.parse(data), { depth: null, colors: true });
});
2 changes: 1 addition & 1 deletion example/tcp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parser } from "../lib/binary_parser";
import { Parser } from "../lib/binary_parser.ts";

const tcpHeader = new Parser()
.endianness("big")
Expand Down
Loading