fast-folder-size
Advanced tools
Comparing version 1.0.0 to 1.0.1
31
index.js
@@ -7,4 +7,5 @@ 'use strict' | ||
function fastFolderSize(target, cb) { | ||
// windows | ||
if (process.platform === 'win32') { | ||
exec( | ||
return exec( | ||
`${path.join( | ||
@@ -16,8 +17,5 @@ __dirname, | ||
(err, stdout) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
if (err) return cb(err) | ||
const match = /Size:\s+(.+) bytes/.exec(stdout) | ||
const bytes = match[1].replace(/\./g, '') | ||
@@ -28,15 +26,14 @@ | ||
) | ||
} else { | ||
exec(`du -s ${target}`, (err, stdout) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
} | ||
const match = /^(\d+)/.exec(stdout) | ||
// other platforms | ||
exec(`du -s ${target}`, (err, stdout) => { | ||
if (err) return cb(err) | ||
const bytes = Number(match[1]) * 1024 | ||
const match = /^(\d+)/.exec(stdout) | ||
cb(null, bytes) | ||
}) | ||
} | ||
const bytes = Number(match[1]) * 1024 | ||
cb(null, bytes) | ||
}) | ||
} | ||
@@ -47,3 +44,3 @@ | ||
if (require.main === module) { | ||
fastFolderSize(process.argv.slice(2)[0], (err, result) => { | ||
fastFolderSize(process.argv.slice(2)[0], (err, bytes) => { | ||
if (err) { | ||
@@ -53,4 +50,4 @@ throw err | ||
console.log(result) | ||
console.log(bytes) | ||
}) | ||
} |
{ | ||
"name": "fast-folder-size", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Node CLI or module to calculate folder size", | ||
"main": "index.js", | ||
"bin": "index.js", | ||
"bin": { | ||
"fast-folder-size": "index.js" | ||
}, | ||
"author": "Simone Busoli <simone.busoli@gmail.com>", | ||
@@ -16,2 +18,5 @@ "scripts": { | ||
], | ||
"repository": { | ||
"url": "https://github.com/simoneb/fast-folder-size.git" | ||
}, | ||
"license": "ISC", | ||
@@ -18,0 +23,0 @@ "dependencies": { |
# fast-folder-size | ||
Node CLI or module to calculate folder size. | ||
It uses: | ||
- [Sysinternals DU](https://docs.microsoft.com/en-us/sysinternals/downloads/du) on Windows, automatically downloaded at installation time because the license does not allow redistribution | ||
- native `du` on other platforms | ||
## Installation | ||
``` | ||
npm i fast-folder-size | ||
``` | ||
## Usage | ||
### Programmatically | ||
```js | ||
const { promisify } = require('util') | ||
const fastFolderSize = require('fast-folder-size') | ||
// callback | ||
fastFolderSize('.', (err, bytes) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log(bytes) | ||
}) | ||
// promise | ||
const fastFolderSizeAsync = promisify(fastFolderSize) | ||
const bytes = await fastFolderSizeAsync('.') | ||
console.log(bytes) | ||
``` | ||
### Command line | ||
```bash | ||
fast-folder-size . | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2595
45
43