Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
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. If using async version (by including callback), it will stream; successfully tested on files 4 GB+.
$ npm install md5-file
Test:
$ npm test
md5File(path, [callback])
var md5File = require('md5-file')
// sync (no callback)
md5File('./path/to/a_file') // '18e904aae79b5642ed7975c0a0074936'
// async/streamed (if using callback)
md5File('./path/to/a_file', function (error, sum) {
if (error) return console.log(error)
console.log(sum) // '18e904aae79b5642ed7975c0a0074936'
})
MIT
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,089,332 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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.