Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dint

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dint - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

76

index.js
'use strict'
const BB = require('bluebird')
const fs = BB.promisifyAll(require('graceful-fs'))
const fs = require('mz/fs')
const ssri = require('ssri')
const path = require('path')
const pEvery = require('p-every')
const pLimit = require('p-limit')
const limit = pLimit(20)
const MAX_BULK_SIZE = 1 * 1024 * 1024 // 1MB

@@ -16,29 +18,44 @@

function _generateFrom (file, fname) {
return fs.statAsync(file).then(stat => {
if (stat.isDirectory()) {
return BB.map(fs.readdirAsync(file), f => {
return _generateFrom(path.join(file, f), path.join(fname, f))
}, {concurrency: 20}).then(files => {
return files.reduce((acc, info) => {
if (info) {
Object.assign(acc, info)
return fs.stat(file)
.then(stat => {
if (stat.isDirectory()) {
return fs.readdir(file)
.then(files => Promise.all(
files.map(f => limit(() => _generateFrom(path.join(file, f), path.join(fname, f))))
)
)
.then(files => {
return files.reduce((acc, info) => {
if (info) {
Object.assign(acc, info)
}
return acc
}, {})
})
}
if (!stat.isFile()) {
// ignored. We don't do things like symlinks rn
return
}
if (stat.size < MAX_BULK_SIZE) {
return {
[fname]: {
size: stat.size,
generatingIntegrity: fs.readFile(file)
.then(data => ssri.fromData(data))
}
return acc
}, {[fname]: Object.assign({isDir: true}, stat)})
})
} else if (!stat.isFile()) {
// ignored. We don't do things like symlinks rn
} else if (stat.size < MAX_BULK_SIZE) {
return fs.readFileAsync(file)
.then(data => ssri.fromData(data))
.then(integrity => ({[fname]: Object.assign({integrity: integrity.toString()}, stat)}))
} else {
return ssri.fromStream(fs.createReadStream(file))
.then(integrity => ({[fname]: Object.assign({integrity: integrity.toString()}, stat)}))
}
}).catch({code: 'ENOENT'}, err => {
if (err.code !== 'ENOENT') {
throw err
}
})
}
}
return {
[fname]: {
size: stat.size,
generatingIntegrity: ssri.fromStream(fs.createReadStream(file))
}
}
})
.catch({code: 'ENOENT'}, err => {
if (err.code !== 'ENOENT') {
throw err
}
})
}

@@ -50,3 +67,2 @@

const fstat = dirIntegrity[f]
if (fstat.isDir) return true

@@ -62,3 +78,3 @@ const filename = path.join(dirname, f)

return fs.readFileAsync(filename)
return fs.readFile(filename)
.then(data => ssri.checkData(data, fstat.integrity))

@@ -65,0 +81,0 @@ .catch(err => {

{
"name": "dint",
"version": "1.0.0",
"version": "2.0.0",
"description": "Generate and verify directory integrity",

@@ -10,3 +10,3 @@ "main": "index.js",

"scripts": {
"test": "node test",
"test": "preview && node test",
"md": "mos"

@@ -35,6 +35,7 @@ },

"dependencies": {
"bluebird": "^3.5.0",
"graceful-fs": "^4.1.11",
"mz": "^2.7.0",
"p-every": "^1.0.2",
"ssri": "^4.1.6"
"p-limit": "^1.1.0",
"ssri": "^5.0.0"
},

@@ -44,2 +45,3 @@ "devDependencies": {

"mos-plugin-readme": "^1.0.4",
"package-preview": "^1.0.1",
"tape": "^4.6.3"

@@ -46,0 +48,0 @@ },

@@ -24,5 +24,5 @@ # dint

Returns a mapping of file names to file stats info and [Subresource Integrity](https://w3c.github.io/webappsec-subresource-integrity/) of each file.
Returns a mapping of file names to size and [Subresource Integrity](https://w3c.github.io/webappsec-subresource-integrity/) of each file.
E.g.:
Result example:

@@ -32,33 +32,7 @@ ```js

'test/fixtures/4/lib/bar.js':
{ integrity: 'sha512-1B0QjibzjRrYeSf79Hcy9T1t8KNt4cFpz//88geXTN6lDnUzMo+4o/MJDESUs884XdZ5EX4RLdzsJA8qeEV3lg==',
dev: 2052,
mode: 33204,
nlink: 1,
uid: 1000,
gid: 1000,
rdev: 0,
blksize: 4096,
ino: 5952246,
size: 198,
blocks: 8,
atime: 2017-06-11T23:13:53.802Z,
mtime: 2017-06-11T23:13:07.903Z,
ctime: 2017-06-11T23:13:07.903Z,
birthtime: 2017-06-11T23:13:07.903Z },
{ generatingIntegrity: Promise<'sha512-1B0QjibzjRrYeSf79Hcy9T1t8KNt4cFpz//88geXTN6lDnUzMo+4o/MJDESUs884XdZ5EX4RLdzsJA8qeEV3lg=='>,
size: 198 },
'test/index.js':
{ integrity: 'sha512-X6ypBcefaTDbDHHcR0J57E2dvDv6vAVi7tHAhfDImmDU8LBaYwdkdX+hVlqFdWNevJjRqsgZbXb/c+Ewq5t3tQ==',
dev: 2052,
mode: 33204,
nlink: 1,
uid: 1000,
gid: 1000,
rdev: 0,
blksize: 4096,
ino: 5923209,
size: 939,
blocks: 8,
atime: 2017-06-11T23:13:53.610Z,
mtime: 2017-06-11T23:13:51.994Z,
ctime: 2017-06-11T23:13:51.994Z,
birthtime: 2017-06-11T23:13:51.994Z } }
{ generatingIntegrity: Promise<'sha512-X6ypBcefaTDbDHHcR0J57E2dvDv6vAVi7tHAhfDImmDU8LBaYwdkdX+hVlqFdWNevJjRqsgZbXb/c+Ewq5t3tQ=='>,
size: 939 } }
```

@@ -70,4 +44,16 @@

E.g.:
```js
check('dirname', {
'test/fixtures/4/lib/bar.js':
{ integrity: 'sha512-1B0QjibzjRrYeSf79Hcy9T1t8KNt4cFpz//88geXTN6lDnUzMo+4o/MJDESUs884XdZ5EX4RLdzsJA8qeEV3lg==',
size: 198 },
'test/index.js':
{ integrity: 'sha512-X6ypBcefaTDbDHHcR0J57E2dvDv6vAVi7tHAhfDImmDU8LBaYwdkdX+hVlqFdWNevJjRqsgZbXb/c+Ewq5t3tQ==',
size: 939 } })
```
## License
[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)
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