Computes SHA-256 hash of JSON string without materializing the string to avoid OOM errors.
// Source: https://github.com/diegosouzapw/OmniRoute | License: MIT | Copyright 2026 diegosouzapw
// Provided via justclaw.it.com; keep this notice with the code.
import crypto from "node:crypto";
/**
* Streaming JSON hash — computes `sha256hex(JSON.stringify(value))` WITHOUT
* materializing the JSON string (#7847 OOM class). Several hot-path call sites
* stringify a multi-megabyte request body just to hash it (compression memo
* keys, cache keys). On a ~5 MiB agent body (with base64 screenshots) that
* allocates a full ~5 MiB string, read once for a hash, then discarded.
*
* `jsonSha256()` walks the value and feeds the same bytes `JSON.stringify`
* would emit directly into a `crypto.createHash("sha256")` stream, so peak
* allocation stays bounded to a small rolling buffer.
*
*
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key