Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
The md5-file npm package is a utility for generating MD5 checksums for files. This can be useful for verifying file integrity, detecting changes, and ensuring data consistency.
Generate MD5 checksum for a file
This feature allows you to generate an MD5 checksum for a specified file. The code sample demonstrates how to use the md5-file package to calculate the MD5 hash of a file asynchronously.
const md5File = require('md5-file');
md5File('path/to/file').then(hash => {
console.log(`The MD5 hash of the file is: ${hash}`);
}).catch(err => {
console.error(err);
});
Generate MD5 checksum for a file synchronously
This feature allows you to generate an MD5 checksum for a specified file synchronously. The code sample demonstrates how to use the md5-file package to calculate the MD5 hash of a file in a synchronous manner.
const md5File = require('md5-file');
try {
const hash = md5File.sync('path/to/file');
console.log(`The MD5 hash of the file is: ${hash}`);
} catch (err) {
console.error(err);
}
The built-in Node.js 'crypto' module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions. It can be used to generate MD5 checksums, but requires more setup compared to md5-file.
The hasha package is a versatile hashing library that supports multiple algorithms including MD5, SHA-1, SHA-256, and more. It can hash strings, buffers, and files, offering more flexibility compared to md5-file, which is specialized for MD5 checksums of files.
The checksum package is a simple utility for generating checksums for files and strings using various algorithms including MD5, SHA-1, and SHA-256. It provides a more general-purpose solution compared to md5-file, which focuses specifically on MD5 checksums for files.
Simply return an md5
sum of a given file.
$ npm install md5-file
Sync:
md5file(path)
var md5file = require('md5-file');
md5file('path/to/a_file'); // '18e904aae79b5642ed7975c0a0074936'
Async:
md5file(path, callback, [strict])
If strict is true
and there is an error it will throw
it, otherwise it will pass an error string through the callback.
md5file.async('./README.md', function (data) {
console.log(data);
});
md5file.async('./README.md', function (data) {
console.log(data);
}, true);
// errors
// non-strict: will pass through an error to `data`
md5file.async('./null', function (data) {
console.log(data);
});
// strict: will throw an error
md5file.async('./null', function (data) {
console.log(data);
}, true);
FAQs
Get the MD5-sum of a given file, with low memory usage, even on huge files.
The npm package md5-file receives a total of 1,100,869 weekly downloads. As such, md5-file popularity was classified as popular.
We found that md5-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.