Giter VIP home page Giter VIP logo

diskinfo's Introduction

diskinfo

Disk usage info on both *nix (via df) and Windows (via WMIC) systems

npm z Build status

Install

npm install @dropb/diskinfo

Usage examples

// JS example (Windows)

const { diskinfo } = require('@dropb/diskinfo');

diskinfo()
  .then(result => console.log(result))
  .catch(err => console.error(err.message));
/* OUTPUT:
[{
    fstype: '3',
    size: 189879426220032,
    used: 53218675523584,
    avail: 136660750696448,
    pcent: '29%',
    target: 'C:'
  },
  {
    fstype: '2',
    size: 16431471132672,
    used: 4540711567360,
    avail: 11890759565312,
    pcent: '28%',
    target: 'F:'
  },
  {
    fstype: '4',
    size: 110151046529024,
    used: 108627465601024,
    avail: 1523580928000,
    pcent: '99%',
    target: 'V:'
  }]
*/
// Typescript example (Ubuntu)

import { diskinfo, DiskInfo } from '@dropb/diskinfo';

async function run() {
  const result: DiskInfo = await diskinfo('./');
  console.log(result)
}
run();
/* OUTPUT:
{ fstype: '/dev/sda1',
  size: 47242534912,
  used: 21033943040,
  avail: 23785177088,
  pcent: '47%',
  target: '/' }
*/

API

/**
 * @param file - get info of the filesystem containing the specified file or directory
 * @returns promise for an object with the info for the specified file or directory
 */
function diskinfo(file: string): Promise<DiskInfo>;

/**
 * @returns promise for an array with the info for all mounted filesystem
 */
function diskinfo(): Promise<DiskInfo[]>;

/**
 * Info of the filesystem
 */
interface DiskInfo {
    /**
     * POSIX - File system type
     *
     * Win32 - Win32_LogicalDisk DriveType(as `String`!):
     * - "0": Unknown
     * - "1": No Root Directory
     * - "2": Removable Disk
     * - "3": Local Disk
     * - "4": Network Drive
     * - "5": Compact Disc
     * - "6": RAM Disk
     */
    fstype: string;
    /**
     * Total size in bytes
     */
    size: number;
    /**
     * Used size in bytes
     */
    used: number;
    /**
     * Available size in bytes
     */
    avail: number;
    /**
     * Percentage of used divided by size
     */
    pcent: string;
    /**
     * Mount point
     */
    target: string;
}

References

License

MIT

diskinfo's People

Contributors

curiositycigar avatar kukhariev avatar

Watchers

 avatar  avatar

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.