Coder Social home page Coder Social logo

cristiammercado / node-disk-info Goto Github PK

View Code? Open in Web Editor NEW
58.0 3.0 14.0 199 KB

Node module to get disk information in Windows, Linux, Mac, FreeBSD & OpenBSD (works with Electron).

License: MIT License

TypeScript 97.93% JavaScript 2.07%
nodejs node module npm windows macos linux electron disk disk-space

node-disk-info's Introduction

Node disk info

Node module to get disk information in Windows, Linux, Mac, FreeBSD & OpenBSD. It works with Electron. The library will call system command to get drives info, parse the results and load info in array. Inspired by diskinfo.

Build Status npm version

Installation

npm install --save node-disk-info

Usage

See the example script for usage. You can run it with npm run example.

// const nodeDiskInfo = require('node-disk-info'); => Use this when install as a dependency
const nodeDiskInfo = require('./dist/index');

// async way
nodeDiskInfo.getDiskInfo()
    .then(disks => {
        printResults('ASYNC WAY', disks);
    })
    .catch(reason => {
        console.error(reason);
    });

// sync way
try {
    const disks = nodeDiskInfo.getDiskInfoSync();
    printResults('SYNC WAY', disks);
} catch (e) {
    console.error(e);
}

function printResults(title, disks) {

    console.log(`============ ${title} ==============\n`);

    for (const disk of disks) {
        console.log('Filesystem:', disk.filesystem);
        console.log('Blocks:', disk.blocks);
        console.log('Used:', disk.used);
        console.log('Available:', disk.available);
        console.log('Capacity:', disk.capacity);
        console.log('Mounted:', disk.mounted, '\n');
    }

}

Output (example run on Windows):

============ SYNC WAY ==============

Filesystem: Disco fijo local
Blocks: 119387713536
Used: 109906608128
Available: 9481105408
Capacity: 92%
Mounted: C:

Filesystem: Disco fijo local
Blocks: 925015994368
Used: 639386984448
Available: 285629009920
Capacity: 69%
Mounted: D:

Filesystem: Disco CD-ROM
Blocks: 0
Used: 0
Available: 0
Capacity: 0%
Mounted: E:

============ ASYNC WAY ==============

Filesystem: Disco fijo local
Blocks: 119387713536
Used: 109906608128
Available: 9481105408
Capacity: 92%
Mounted: C:

Filesystem: Disco fijo local
Blocks: 925015994368
Used: 639386984448
Available: 285629009920
Capacity: 69%
Mounted: D:

Filesystem: Disco CD-ROM
Blocks: 0
Used: 0
Available: 0
Capacity: 0%
Mounted: E:

Release History & Changelog

See the Releases page for a list of all releases, including changes.

Help / Support

If you run into any issues, please email me at [email protected] or you can use the contact form in my page.

For bug reports, please open an issue on GitHub.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Added some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.

License

MIT

node-disk-info's People

Contributors

cristiammercado avatar dependabot[bot] avatar ekristoffe avatar kimlimjustin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-disk-info's Issues

Darwin: volumes containing spaces are truncated

If a Volume contains a space, for ex.:

/dev/disk5s1 316576 310128 6448 98% /Volumes/React-Explorer 2.3.1

Only the first part of the string would be added into the Drive, resulting in an incorrect mounted property:

Filesystem: /dev/disk5s1
Blocks: 316576
Used: 310128
Available: 6448
Capacity: 98%
Mounted: /Volumes/React-Explorer

Wrong disk info on windows

Here is what I tried:

for(const disk of disks){
... console.log(disk)
... console.log(disk.filesystem)
... }
Drive {
_filesystem: 'Local Fixed Disk',
_blocks: 0,
_used: 0,
_available: 0,
_capacity: '0%',
_mounted: 'C:'
}
Local Fixed Disk
Drive {
_filesystem: 'Local Fixed Disk',
_blocks: 0,
_used: 0,
_available: 0,
_capacity: '0%',
_mounted: 'D:'
}
Local Fixed Disk
Drive {
_filesystem: 'Local Fixed Disk',
_blocks: 0,
_used: 0,
_available: 0,
_capacity: '0%',
_mounted: 'E:'
}
Local Fixed Disk
Drive {
_filesystem: 'Local Fixed Disk',
_blocks: 0,
_used: 0,
_available: 0,
_capacity: '0%',
_mounted: 'F:'
}
Local Fixed Disk
Drive {
_filesystem: 'CD-ROM Disc',
_blocks: 0,
_used: 0,
_available: 0,
_capacity: '0%',
_mounted: 'G:'
}
CD-ROM Disc
undefined

Mounted name went wrong when there's a space on Linux and Darwin

Mounted name of a disk when wrong when there's a space, in my case, New Volume become New. I've read the code and figured out this bug occurred because the code directly passed the tokens[5] which is an array came from splitting space in the line variable into the drive_1 class, and I found a way to fix it! I'd like to be assigned to fix this bug if you like to :)

Regards

FreeBSD support ?

Hello
Could it be possible to add FreeBSD support to this library ?

Doesn't work on Windows because "Wmic" removed.

Microsoft removed the WMIC tool from Windows 11 Dev builds and this command is not working.

path : node_modules\node-disk-info\src\utils\constants.ts line 9

"wmic logicaldisk get Caption,FreeSpace,Size,VolumeSerialNumber,Description /format:list"

image

I tried to contribute but I have doubts about what to use instead of wmic.

Non ascii volume name support

This is originally reported on kimlimjustin/xplorer#114. I've tried to reproduce it by myself and it's the same, this is because wmic doesn't output the volume name correctly, 你好 became ?? on wmic output.

Maybe for Windows, could it be done by using c++ native bindings (?)

Thanks and Regards

Error · EPIPE: broken pipe, write

I am running this module periodically on NODE 14.4 and on Windows.
Sometimes I get an unhandled error from the code:
return execSync(command,{windowsHide: true, encoding: 'buffer'});

If possible this error should be handled and not crash the whole node server.

Differing units between Windows and darwin

I took a look at how darwin is getting the disk info, and see that it uses df -P, which I believe outputs in counts of 512 bytes.
Comparing this with what Windows is doing with wmic, I think Windows outputs in plain bytes. This should be properly documented if this is really the case.

For context, I've experienced false positives on darwin in a platform-agnostic app.

Is project still alive?

Hi,

While using node-disk-info, I stumbled upon a bug with volumes containing a space in Darwin/Linux. So I created an issue, and since it was quite an easy fix, made a PR... Before noticing there was already a PR with the very same fix that has been ready to be merged since more than a year.

So I wonder: is the project still alive?

In the meantime I created a fork and integrated the fix in it, but I'd like to avoid publishing another package on npm just to have this fix applied (npm is full of such packages).

If you have no time or other interests (maintaining software takes a lot of time) would you consider handing over this work to someone with more time?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.