UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

54 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hashOf = hashOf; exports.contentHash = contentHash; exports.dictionaryHash = dictionaryHash; exports.shardHash = shardHash; /** * Stable content hashes over a bundle's data, used both when writing a bundle (to stamp its header/manifest) * and when reading one back (to verify it). A portable {@link Hash53} runs over newline-terminated JSON chunks * so chunk boundaries can never collide. Split out of `../sigdb` as it is shared by the writer and the reader. */ const hash_1 = require("../../util/hash"); const decode_1 = require("./decode"); /** the JSON chunks a bundle is hashed over: every dictionary string, every blob tuple, then the pkgs + meta maps */ function* hashChunks(db) { for (const s of db.strings) { yield JSON.stringify(s); } for (const b of db.blobs) { yield JSON.stringify((0, decode_1.blobTuple)(b)); } yield JSON.stringify(db.pkgs); yield JSON.stringify(db.meta); } /** run a Hash53 over a stream of chunks (each null-terminated so boundaries can't collide) */ function hashOf(chunks) { const h = new hash_1.Hash53(); for (const chunk of chunks) { h.update(chunk).update('\x00'); } return h.digest(); } /** the self-contained content hash of a whole bundle (dictionary + blobs + routing/metadata) */ function contentHash(db) { return hashOf(hashChunks(db)); } /** stable hash of a shared dictionary */ function dictionaryHash(strings) { return hashOf((function* () { for (const s of strings) { yield JSON.stringify(s); } })()); } /** stable hash of one shard's data (its blobs + pkgs map; the dictionary is hashed separately) */ function shardHash(blobs, pkgs) { return hashOf((function* () { for (const b of blobs) { yield JSON.stringify((0, decode_1.blobTuple)(b)); } yield JSON.stringify(pkgs); })()); } //# sourceMappingURL=hash.js.map