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
Get the MD5-sum of a given file, with low memory usage, even on huge files.
Installation
npm install --save md5-file
Usage
As a module
const md5File = require('md5-file')
md5File('LICENSE.md').then((hash) => {
console.log(`The MD5 sum of LICENSE.md is: ${hash}`)
})
const hash = md5File.sync('LICENSE.md')
console.log(`The MD5 sum of LICENSE.md is: ${hash}`)
As a command line tool
$ md5-file LICENSE.md
ad1faf9381e43c471dc381c17a4ee4b6
API
md5File(path: string) => Promise<string>
Asynchronously get the MD5-sum of the file at path
.
Returns a Promise
that will be resolved with a string containing the MD5-sum.
md5File.sync(path: string) => string
Synchronously get the MD5-sum of the file at path
.
License
MIT