Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
node-diskusage-ng/lib/posix.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (37 sloc)
987 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var execFile = require('child_process').execFile; | |
| var isDigits = require('./utils').isDigits; | |
| function diskusage(path, cb) { | |
| execFile('df', ['-P', '-k', path], function(err, stdout) { | |
| if (err) { | |
| return cb(err); | |
| } | |
| try { | |
| cb(null, parse(stdout)); | |
| } catch (e) { | |
| cb(e); | |
| } | |
| }); | |
| } | |
| function parse(dusage) { | |
| var lines = dusage.split('\n'); | |
| if (!lines[1]) { | |
| throw new Error('Unexpected df output: [' + dusage + ']'); | |
| } | |
| var matches = lines[1].match(/^.+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+.+$/); | |
| if (!matches || matches.length !== 4) { | |
| throw new Error('Unexpected df output: [' + dusage + ']'); | |
| } | |
| var total = matches[1]; | |
| var used = matches[2]; | |
| var available = matches[3]; | |
| return { | |
| total: total*1024, | |
| used: used*1024, | |
| available: available*1024 | |
| }; | |
| } | |
| module.exports = { | |
| diskusage: diskusage, | |
| parse: parse | |
| }; |