@objekt/checksum-report
v1.0.1
Published
NodeJS utility library to generate checksums for files and directories.
Downloads
1
Readme
Introduction
This utility libary assists you to generate a checksum report for a directory and its descendants.
This is useful to include in the root of distribution bundle, e.g. a static website, as a client application could use this report to validate it has downloaded the complete bundle.
Each file in the directory structure is read and its content hashed using the sha1 algorithm with hex encoding by default.
The report is generated as a JSON string in the below format, where:
- id = uniquely identifies the report, i.e. the overall hash of all file hashes.
- timestamp = the timestamp on which the report was generated.
- files = is a flat array of each path and it's hash.
e.g.
{
"id":"9d307fdcafb3f6f2fbcd47899df78652936cea00",
"timestamp":"2022-04-10T15:21:08.406Z",
"files":[
{
"path":"index.html",
"hash":"064c47308009992f133a44e368cf1dcfdaa9d85e"
},
{
"path":"app.39b812d9.js",
"hash":"1bd6e3344fbc3363b1faa00d1115378135aac5ce"
},
{
"path":"vendors.70682963.js",
"hash":"5b055ca612c8e6883decd76258261d85da3de644"
},
{
"path":"assets/logo.png",
"hash":"ed73e59a43d571044f457e62d385a6ea025f651c"
}
]
}
Installation
npm install @objekt/checksum-report
Configuration
No configuration needed. This libary targets NodeJS 16 and above.
Usage
Generate Checksum Report
Generate a checksum report for the dist directory.
import { ChecksumReport } from '@objekt/checksum-report';
const report = await ChecksumReport.get('./dist');
console.log(report);
Generate and Save Checksum Report to Disk
Generate and save a checksum for the dist directory as checksum.json to disk.
import { ChecksumReport } from '@objekt/checksum-report';
const report = await ChecksumReport.save('./dist', './dist/checksum.json');
console.log(report);
API Reference
Full API documentation here.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind welcome! (emoji key)