md5-file
Advanced tools
Comparing version 4.0.0 to 5.0.0
28
index.js
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
const crypto = require('crypto') | ||
@@ -8,4 +6,4 @@ const fs = require('fs') | ||
function md5FileSync (filename) { | ||
const fd = fs.openSync(filename, 'r') | ||
function md5FileSync (path) { | ||
const fd = fs.openSync(path, 'r') | ||
const hash = crypto.createHash('md5') | ||
@@ -28,17 +26,17 @@ const buffer = Buffer.alloc(BUFFER_SIZE) | ||
function md5File (filename, cb) { | ||
if (typeof cb !== 'function') throw new TypeError('Argument cb must be a function') | ||
function md5File (path) { | ||
return new Promise((resolve, reject) => { | ||
const output = crypto.createHash('md5') | ||
const input = fs.createReadStream(path) | ||
const output = crypto.createHash('md5') | ||
const input = fs.createReadStream(filename) | ||
input.on('error', (err) => { | ||
reject(err) | ||
}) | ||
input.on('error', function (err) { | ||
cb(err) | ||
}) | ||
output.once('readable', () => { | ||
resolve(output.read().toString('hex')) | ||
}) | ||
output.once('readable', function () { | ||
cb(null, output.read().toString('hex')) | ||
input.pipe(output) | ||
}) | ||
input.pipe(output) | ||
} | ||
@@ -45,0 +43,0 @@ |
{ | ||
"name": "md5-file", | ||
"main": "index.js", | ||
"repository": "roryrjb/md5-file", | ||
"files": [ | ||
"cli.js", | ||
"index.js", | ||
"promise.js" | ||
], | ||
"version": "4.0.0", | ||
"description": "return an md5sum of a given file", | ||
"version": "5.0.0", | ||
"keywords": [ | ||
@@ -17,18 +9,20 @@ "md5", | ||
], | ||
"author": { | ||
"name": "Rory Bradford", | ||
"email": "rory@dysfunctionalprogramming.com" | ||
}, | ||
"repository": "roryrjb/md5-file", | ||
"license": "MIT", | ||
"bin": "cli.js", | ||
"files": [ | ||
"cli.js", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "standard && mocha" | ||
}, | ||
"bin": "cli.js", | ||
"devDependencies": { | ||
"mocha": "^5.0.5", | ||
"standard": "^11.0.1" | ||
"mocha": "^7.1.1", | ||
"standard": "^14.3.3" | ||
}, | ||
"engines": { | ||
"node": ">=6.0" | ||
"node": ">=10.13.0" | ||
} | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
51
3925
2
50