What is md5-file?
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.
What are md5-file's main functionalities?
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);
}
Other packages similar to md5-file
crypto
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.
hasha
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.
checksum
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.
md5-file
Simply return an md5
sum of a given file.
Installation
$ npm install md5-file
Test:
$ npm test
API
Sync:
md5File(path)
var md5File = require('md5-file');
md5File('path/to/a_file');
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);
md5File.async('./null', function (data) {
console.log(data);
});
md5File.async('./null', function (data) {
console.log(data);
}, true);
License
MIT