Comparing version 2.0.5 to 2.0.6
20
index.js
@@ -6,7 +6,21 @@ 'use strict' | ||
var BUFFER_SIZE = 8192 | ||
function md5FileSync (filename) { | ||
var sum = crypto.createHash('md5') | ||
var data = fs.readFileSync(filename) | ||
var fd = fs.openSync(filename, 'r') | ||
var hash = crypto.createHash('md5') | ||
var buffer = new Buffer(BUFFER_SIZE) | ||
return sum.update(data).digest('hex') | ||
try { | ||
var bytesRead | ||
do { | ||
bytesRead = fs.readSync(fd, buffer, 0, BUFFER_SIZE) | ||
hash.update(buffer.slice(0, bytesRead)) | ||
} while (bytesRead === BUFFER_SIZE) | ||
} finally { | ||
fs.closeSync(fd) | ||
} | ||
return hash.digest('hex') | ||
} | ||
@@ -13,0 +27,0 @@ |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "return an md5sum of a given file", | ||
@@ -14,0 +14,0 @@ "keywords": [ |
# md5-file [![Build Status](https://travis-ci.org/roryrjb/md5-file.svg?branch=master)](https://travis-ci.org/roryrjb/md5-file) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
> 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+. | ||
Get the MD5-sum of a given file, with low memory usage, even on huge files. | ||
### Installation | ||
## Installation | ||
```sh | ||
npm install --save md5-file | ||
``` | ||
$ npm install md5-file | ||
``` | ||
__Test:__ | ||
## Usage | ||
```js | ||
const md5File = require('md5-file') | ||
/* Async usage */ | ||
md5File('LICENSE.md', (err, hash) => { | ||
if (err) throw err | ||
console.log(`The MD5 sum of LICENSE.md is: ${hash}`) | ||
}) | ||
/* Sync usage */ | ||
const hash = md5File('LICENSE.md') | ||
console.log(`The MD5 sum of LICENSE.md is: ${hash}`) | ||
``` | ||
$ npm test | ||
``` | ||
### API | ||
## API | ||
__md5File(path, [callback])__ | ||
### `md5File(filepath: string, cb: function)` | ||
```javascript | ||
var md5File = require('md5-file') | ||
Asynchronously get the MD5-sum of the file at `filepath`. | ||
// sync (no callback) | ||
The callback `cb` will be called with `(err: Error, hash: string)`. | ||
md5File('./path/to/a_file') // '18e904aae79b5642ed7975c0a0074936' | ||
### `md5File(filepath: string) => string` | ||
// async/streamed (if using callback) | ||
Synchronously get the MD5-sum of the file at `filepath`. | ||
md5File('./path/to/a_file', function (error, sum) { | ||
if (error) return console.log(error) | ||
console.log(sum) // '18e904aae79b5642ed7975c0a0074936' | ||
}) | ||
``` | ||
### License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4227
59
43
0