New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

du

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

du - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

.jshintrc

35

index.js

@@ -7,12 +7,33 @@ /* Copyright (c) 2012 Rod Vagg <@rvagg> */

module.exports = function (dir, callback) {
function du (dir, options, callback) {
if (typeof options == 'function') {
callback = options
options = {}
}
fs.stat(dir = path.resolve(dir), function (err, stat) {
if (!stat || !stat.isDirectory()) return callback(err, stat && stat.size)
if (err) return callback(err)
if (!stat) return callback(null, 0)
if (!stat.isDirectory())
return callback(null, !options.filter || options.filter(dir) ? stat.size : 0)
fs.readdir(dir, function (err, list) {
if (err) return callback(err)
async.map(
list.map(function (f) { return path.join(dir, f) })
, module.exports
list.map(function (f) {
return path.join(dir, f)
})
, function (f, callback) {
return du(f, options, callback)
}
, function (err, sizes) {
callback(err, sizes && sizes.reduce(function (p, s) { return p + s }, stat.size))
callback(
err
, sizes && sizes.reduce(function (p, s) {
return p + s
}, stat.size)
)
}

@@ -22,2 +43,4 @@ )

})
}
}
module.exports = du

12

package.json
{
"author": "Rod Vagg @rvagg <rod@vagg.org>"
"authors" : [
"Rod Vagg @rvagg <rod@vagg.org> (https://github.com/rvagg)"
]
, "name": "du"
, "description": "A simple JavaScript implementation of `du -sb`"
, "keywords": [ "du", "size" ]
, "version": "0.0.0"
, "version": "0.0.1"
, "main": "index.js"

@@ -20,2 +22,6 @@ , "bin": {

}
}
, "repository" : {
"type" : "git"
, "url" : "https://github.com/rvagg/node-du.git"
}
}

@@ -10,5 +10,18 @@ # node-du

One day, I'll expand it with an `options` parameter to do similar stuff to the actual `du` command. Or perhaps you could submit a pull request if you require something?
Also comes with a `dujs` command if installed with `npm install du -g`, just in case `du -sb` was too many 2 too many characters for you to type.
## options
An optional `options` object may be passed as the second argument. Currently there is only one option, a `'filter'` function that is passed a full file path and is expected to return a truthy/falsy value to indicate whether the file is included in size calculations.
```js
du(
'/tmp/foo.leveldb/'
, { filter: function (f) { return /\.sst$/.test(f) } }
, function (err, size) {
console.log('The size of the sst files in /tmp/foo.leveldb/ is:', size, 'bytes')
}
)
```
*Copyright (c) 2012 [Rod Vagg](https://github.com/rvagg) ([@rvagg](https://twitter.com/rvagg))*

@@ -15,0 +28,0 @@

@@ -33,8 +33,22 @@ var assert = require('assert')

// account for 6 x directory entries, reasonably taking up a max of 8192b each
assert(size - bigboy.length * 5 <= 8192 * 6)
var adjusted = size - bigboy.length * 5
, expected = 8192 * 5
assert(adjusted <= expected, 'adjusted size (' + size + ' -> ' + adjusted + ') <= ' + expected)
})
du(dir, { filter: function (f) { return /(a|e|f)$/.test(f) } }, function (err, size) {
mkfiletree.cleanUp(function () {})
if (err) throw err
// write 5 x bigboys
// account for 6 x directory entries, reasonably taking up a max of 8192b each
var adjusted = size - bigboy.length * 3
, expected = 8192 * 3
assert(adjusted <= expected, 'leftover size (' + size + ' -> ' + adjusted + ') <= ' + expected)
})
})
console.log('Running... no assertions means no worries!')
console.log('Running... no assertions means no worries')

@@ -41,0 +55,0 @@ process.on('uncaughtException', function (err) {

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