Socket
Socket
Sign inDemoInstall

md5-file

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

md5-file - npm Package Compare versions

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 @@

2

package.json

@@ -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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc