← Runnable Projects

阅读中文版本

Node Hexdump CLI

Node Hexdump — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-hexdump-cli

Entry point: hexdump.mjs

Install

node hexdump.mjs file.bin

Run

node hexdump.mjs sample.bin

Test

node --test hexdump.test.mjs

Expected output

Produces an xxd-style hex dump with offset, hex bytes, and ASCII gutter.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node Hexdump CLI is a self-contained typescript command-line program. Produces an xxd-style hex dump with offset, hex bytes, and ASCII gutter.

Install and run

node hexdump.mjs file.bin
node hexdump.mjs sample.bin

Project structure

node-hexdump-cli/
├── hexdump.mjs
└── README snippet above

Key source

// hexdump.mjs
import { readFileSync } from "node:fs";
const b = readFileSync(process.argv[2]);
for (let i=0;i<b.length;i+=16){const sl=b.subarray(i,i+16);const hex=[...sl].map(x=>x.toString(16).padStart(2,"0")).join(" ").padEnd(48);const asc=[...sl].map(x=>x>=32&&x<127?String.fromCharCode(x):".").join("");console.log(`${i.toString(16).padStart(8,"0")}  ${hex}  |${asc}|`);}

Testing

node --test hexdump.test.mjs

Expected output

When run with the documented command, the program prints:

00000000  68 65 6c 6c 6f                                  |hello|

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.