← Runnable Projects

阅读中文版本

Node Streaming SHA-256 CLI

Node Streaming SHA-256 — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-sha256-stream-cli

Entry point: sha256.mjs

Install

node sha256.mjs file.bin

Run

node sha256.mjs sample.bin

Test

node --test sha256.test.mjs

Expected output

Hashes a file with the streaming crypto API so large files do not load fully into memory.

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 Streaming SHA-256 CLI is a self-contained typescript command-line program. Hashes a file with the streaming crypto API so large files do not load fully into memory.

Install and run

node sha256.mjs file.bin
node sha256.mjs sample.bin

Project structure

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

Key source

// sha256.mjs
import { createHash } from "node:crypto";
import { createReadStream } from "node:fs";
const h=createHash("sha256");
createReadStream(process.argv[2]).on("data",c=>h.update(c)).on("end",()=>console.log(h.digest("hex")));

Testing

node --test sha256.test.mjs

Expected output

When run with the documented command, the program prints:

2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824   (sha256 of "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.