keverw / diskspace.js Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
On Linux, the three fields result.total
, result.used
, result.free
are numbers, which is great.
But on windows, the field result.used
is a number while result.total
and result.free
are strings. They should all be numbers.
Tested on: Windows 7 Professional (Windows_NT x64 6.1.7601)
should change code to:
var exec = path.join(__dirname, 'drivespace.exe');
exec = '"' + exec + '" drive-' + drive;
child_process.exec(exec, function(error, stdout, stderr)
I upgraded to v0.1.7 and my code broke. I checked and realised that the first parameter of the callback function is now an error
before
var diskspace = require('diskspace');
diskspace.check('/', function(total, free) {
fn(bytes(total), bytes(free));
});
after
var diskspace = require('diskspace');
diskspace.check('/', function(err, total, free) {
if (err) return fn(err);
fn(bytes(total), bytes(free));
});
You should consider using http://semver.org/
The version @1.0.0 doesn't work for me on Mac OS X - El Capitan (10.11.1) because of this code :
if(disk_info[5] != drive.replace(/'/g,"'\\''")){ //if not mount point
free = total = 0;
}
In fact, the df -k
command gives me something like :
Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 487350400 457065864 30028536 94% 114330464 7507134 94% /
And then free
and total
vars are always equal to 0.
Hello,
I am trying to launch the Driveshare gui with npm start
after installing the node package. However, nothing comes up. No errors or anything. What could be wrong?
Would it be possible to add in an option to toggle human readable disk info for Linux (df -h) vs. just returning the df -k info?
So you would pass in both the disk to look at, as well as the format the output would take.
Hello,
I noticed that on windows, when the script try to launch diskspace.exe, there's an error when the full path contains a space such as : "C:\Program Files (x86)"
Output :
C:\Windows\system32\cmd.exe /s /c "C:\Program Files (x86)\APP_NAME\resources\app\node_modules\diskspace\drivespace.exe drive-C"
'C:\Program' n'est pas reconnu en tant que commande interne (french for Command not found)
Hello!
I use Diskspace npm package (version 2.0.0) in my node.js project and I have 3 different environments: Windows 10 on developer's computer, Debian 8 on staging environment and production on Ubuntu 14.04.5 LTS on Azure VM. When I use it on dev or staging envs, all is ok, and it correct works on production with root disk ("/"), but when I have added one more disk ("/data" mountpoint, for example), I have this error:
Problem with command Error:
Command failed: df -k '/data'df: '/data':
No such file or directory
Error: Command failed: df -k '/data',df: '/data':
No such file or directory,,
at ChildProcess.exithandler (child_process.js:204:12),
at emitTwo (events.js:106:13),
at ChildProcess.emit (events.js:191:7),
at maybeClose (internal/child_process.js:886:16),
at Socket. (internal/child_process.js:342:11),
at emitOne (events.js:96:13),
at Socket.emit (events.js:188:7),
at Pipe._handle.close [as _onclose] (net.js:501:12)
Of course, volume '/data' exists and correct works. Command "df -k '/data' " also correct works in terminal.
Any help will be appreciated
This module uses the df -k command to get the disk usage info. Problem is that the output for df -k is slightly different on CentOS than on other linux distributions.
On CentOS, for example, "df -k /" can output this:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
51606140 5131448 43853252 11% /
Notice there are 3 lines in the output above. On debian squeeze and other linux distributions the output is only two lines, like this:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7867856 1768364 5699828 24% /
The problem is that the code always looks for the data on the second line of output. The safer thing to do is to look at the last line of output.
The FIX is to change these two lines:
var lines = stdout.split("\n");
var str_disk_info = lines[1].replace( /[\s\n\r]+/g,' ');
to this:
var lines = stdout.trim().split("\n");
var str_disk_info = lines[lines.length - 1].replace( /[\s\n\r]+/g,' ');
I'm not sure how to commit this change to github, or if I'm even allowed (have access) to do this.
Windows 10
Using [email protected]
disk.check('C:/'...
works.
disk.check('D'...
works.
All of the following throw a "Drive not found" error
disk.check('C:/Users'...
disk.check('D/tmp'...
disk.check('D:\tmp'...
For function check
should be JSDoc
information added with input parameters types and output callback results
First, thanks and congrats for this work!
I am trying to get disk stats of a system Ubuntu Core 18 running over Raspberry PI 3 Model B with a MicroSD disk. The df -h
of system is:
I test passing "/" and "/writable" to lib, but it do not get free space correctly:
{"total":50200576,"used":50200576,"free":0,"status":"READY"}
(to "/writable").
Any tip to fix?
Hello,
Currently, diskspace returns the Total
and Available
disk space. One would think that we can guess the Used
diskspace by doing: Total - Available
. However, this is not accurate, probably for the following reason: https://askubuntu.com/questions/249387/df-h-used-space-avail-free-space-is-less-than-the-total-size-of-home#249415
Example:
$ df -k .
Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 243924992 117961984 125707008 49% 29554494 31426752 48% /
Would that be good idea to also return the Used
diskspace?
Thanks
I'm sorry I comment this without reading readme file, now I write the drivespace.exe with cpp, it can work without .net.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
char* ptr = lpCmdLine;
while (*ptr != 0x0)
{
if (islower(*ptr))
{
*ptr = toupper(*ptr);
}
ptr++;
}
char *p, *safePtr;
p = strtok_s(lpCmdLine, "-", &safePtr);
if (!p || strcmp(p,"DRIVE") || !safePtr || strlen(safePtr)<=0)
{
printf("0,0,NOTFOUND");
return -1;
}
char disk[] = "C:";
disk[0] = *safePtr;
DWORD64 qwFreeBytes=0, qwFreeBytesToCaller=0, qwTotalBytes=0;
BOOL bResult = GetDiskFreeSpaceEx(disk,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (!bResult)
{
printf("0,0,NOTFOUND");
return -1;
}
printf("%lld,%lld,READY",qwTotalBytes,qwFreeBytes);
return 0;
}
What's the easiest way to make this into a method that is synchronous? The callback doesn't contain the error first, so I can't apply normal async call patterns to it to make it sync.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.