Socket
Socket
Sign inDemoInstall

sha1-file

Package Overview
Dependencies
3
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 2.0.0

index.d.ts

31

index.js

@@ -1,27 +0,10 @@

'use strict'
"use strict"
var crypto = require('crypto')
var fs = require('fs')
const hasha = require("hasha")
module.exports = function (filename, callback) {
var sum = crypto.createHash('sha1')
if (callback && typeof callback === 'function') {
var fileStream = fs.createReadStream(filename)
fileStream.on('error', function (err) {
return callback(err, null)
})
fileStream.on('data', function (chunk) {
try {
sum.update(chunk)
} catch (ex) {
return callback(ex, null)
}
})
fileStream.on('end', function () {
return callback(null, sum.digest('hex'))
})
} else {
sum.update(fs.readFileSync(filename))
return sum.digest('hex')
}
const hashaOptions = {
algorithm: "sha1"
}
module.exports = filepath => hasha.fromFile(filepath, hashaOptions)
module.exports.sync = filepath => hasha.fromFileSync(filepath, hashaOptions)
{
"name": "sha1-file",
"main": "index.js",
"files": [
"index.js",
"test.js",
"LICENSE.md",
"README.md"
],
"version": "1.0.4",
"description": "return an sha1sum of a given file",
"keywords": [
"sha1",
"sha1sum",
"checksum"
],
"homepage": "https://github.com/roryrjb/sha1-file",
"author": {
"name": "Rory Bradford",
"email": "roryrjb@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/roryrjb/sha1-file.git"
},
"license": "MIT",
"bugs": {
"url": "http://github.com/roryrjb/sha1-file/issues",
"email": "roryrjb@gmail.com"
},
"scripts": {
"test": "./node_modules/.bin/standard && ./node_modules/.bin/ahcom"
},
"devDependencies": {
"ahcom": "0.0.10",
"standard": "^12.0.1"
}
"name": "sha1-file",
"version": "2.0.0",
"description": "Get the SHA1 of a file.",
"repository": "https://github.com/Richienb/sha1-file.git",
"author": "Richie Bendall <richiebendall@gmail.com>",
"license": "MIT",
"main": "index.js",
"files": [
"index.js",
"index.d.ts"
],
"engines": {
"node": ">=10"
},
"scripts": {
"lint": "xo",
"test": "yarn lint && ava"
},
"keywords": [
"sha1",
"sha1sum",
"checksum",
"file",
"generator",
"path",
"create",
"compute",
"hash"
],
"dependencies": {
"hasha": "^5.2.0"
},
"devDependencies": {
"ava": "^3.5.2",
"eslint-config-richienb": "^0.4.2",
"xo": "^0.28.1"
},
"resolutions": {
"eslint": "^6.8.0"
},
"xo": {
"extends": "richienb"
}
}

@@ -1,51 +0,30 @@

# sha1-file
# sha1-file [![Travis CI Build Status](https://img.shields.io/travis/com/Richienb/sha1-file/master.svg?style=for-the-badge)](https://travis-ci.com/Richienb/sha1-file)
[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![License][license-image]][license-url]
[![Code style][standard-image]][standard-url]
Get the SHA1 of a file.
> Simply return an `sha1` sum of a given file. If using async version (by including callback), it will stream; successfully tested on files 4 GB+.
[![NPM Badge](https://nodei.co/npm/sha1-file.png)](https://npmjs.com/package/sha1-file)
### Installation
## Install
```sh
npm install sha1-file
```
$ npm install --save sha1-file
```
### Usage
## Usage
__sha1File(path, [callback])__
```js
const sha1File = require("sha1-file");
```javascript
const sha1File = require('sha1-file')
sha1File.sync("file.txt");
//=> "a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b"
```
// sync (no callback)
## API
sha1File('./path/to/a_file') // 'c8a2e2125f94492082bc484044edb4dc837f83b'
### sha1File(filepath)
// async/streamed (if using callback)
Returns a promise for the file hash.
sha1File('./path/to/a_file', function (error, sum) {
if (error) {
console.log(error)
}
### sha1File.sync(filepath)
console.log(sum) // 'c8a2e2125f94492082bc484044edb4dc837f83b'
})
```
### Caveats
When using the _sync_ version (excluding the callback), you will be limited to
a filesize of 2GB (1GB on 32-bit platforms), this is due to a *V8* restriction,
see [this issue](https://github.com/nodejs/node/issues/1719) for more details.
[npm-image]: https://img.shields.io/npm/v/sha1-file.svg
[npm-url]: https://npmjs.org/package/sha1-file
[travis-image]: https://img.shields.io/travis/roryrjb/sha1-file.svg
[travis-url]: https://travis-ci.org/roryrjb/sha1-file
[license-image]: http://img.shields.io/npm/l/sha1-file.svg
[license-url]: LICENSE
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
[standard-url]: https://github.com/feross/standard
Returns the file hash.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc