file-hasher
Version:
Node.js library for generating file hashes
55 lines (40 loc) • 1.05 kB
Markdown
Node.js library for generating file hashes.
**npm**:
~~~
npm install file-hasher
~~~
**yarn**:
~~~
yarn add file-hasher
~~~
Asynchronously get the hash of the file at `path`. If no algorithm is specified, md5 shall be used as default. If no encoding is specified, 'hex' is used.
```js
const hashFile = require('file-hasher')
hashFile('index.js', (error, output) => {
if (error) {
throw error;
}
console.log(`hash is: ${output}`);
});
// hash is: 5be057751697d46af6d5fa2065a4b16c
});
```
```js
const hashFile = require('file-hasher')
hashFile('index.js', (error, output) => {
if (error) {
throw error;
}
console.log(`md5 hash with base64 encoding is: ${output}`);
}, 'sha256', 'base64');
// md5 hash with base64 encoding is: NUMulsRU7WYPv/hLS6ws7LZVMx53z5SnGhiB7bZ93qM=
```
MIT