# diskfree

> Gets space available on a disk/directory. Node c++ extension that uses statvfs and GetFreeDriveSpaceEx, and provides proper errorcodes

Latest version **1.2.0** (published 2019-12-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install diskfree
pnpm add diskfree
yarn add diskfree
bun add diskfree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-12-26 |
| First published | 2016-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 4 |
| Author | Serghei Filippov |
| Maintainers | saevon |
| Keywords | disk, usage, size, disk-size, df |

## Links

- npm: https://www.npmjs.com/package/diskfree
- Repository: https://github.com/Saevon/node-diskfree
- Issues: https://github.com/Saevon/node-diskfree/issues
- npm.io page: https://npm.io/package/diskfree

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2019-12-26
- 1.1.0 — 2018-11-07
- 1.0.2 — 2016-11-17
- 1.0.1 — 2016-11-15
- 1.0.0 — 2016-11-15

## README

# node-diskfree


This implements a shared interface to the unix-like and windows disk space readers. It is implemented in C++ using the Node Addons API

Unix runs on the [`statvfs`](https://linux.die.net/man/2/statvfs) systemcall
Windows runs on the [`GetDiskFreeSpaceEx`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937/) systemcall

This utility will return the correct error number from the respective systemcall.

## Installation

Install with npm

```bash
npm install disk-space
```

Install Locally

```bash
npm install Saevon/node-diskfree.git --save
```

## Usage

```js
var diskfree = require('diskfree');
diskfree.check('C:', function onDiskInfo(error, info) {
    if (error) {
        // You can see if its a known error
        if (diskfree.isErrBadPath(err)) {
            throw new Error('Path is Wrong');
        } else if (diskfree.isErrDenied(error)) {
            throw new Error('Permission Denied');
        } else if (diskfree.isErrIO(error)) {
            throw new Error('IO Error');
        }

        throw new Error('Unknown error: ' + error);
    }

    info.free == "Free Space";
    info.available == "User Available Space";
    info.total == "Total Space":
    info.used == "Used Space";
    info.locked == "OS locked";
});
```

### diskfree.check(diskPath, callback):

Grabs disk space information

#### Arguments

| Name        | Type   | Description           |
|-------------|--------|-----------------------|
| diskPath   | `String`   | Directory to check  |
| callback   | `function` | `callback(error, diskInfo)` |

##### `diskInfo`

All space values are in bytes. If the value exceeds the maximum size of a double `0xFFFF FFFF FFFF F800` then this returns `Infinity`

| Name        | Type     | Description           |
|-------------|----------|-----------------------|
| free        | `Number` | Free space  |
| available   | `Number` | User Available free space  |
| used        | `Number` | Used space  |
| total       | `Number` | Total space  |
| locked      | `Number` | OS locked Space (Unavailable to user) |

##### `error`

Error will be `undefined` if the operation succeeds, otherwise check the system error list to find the problem.

Note that your specific system will might have its own error codes

Windows [`System Error Codes`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms681381)
Unix-Like [`errno.h`](http://www.virtsync.com/c-error-codes-include-errno)


### diskfree.isErrBadPath(error):

Returns `true` if the errorcode is one of the windows/unix errorcodes that indicate the path was wrong.

Note: this might only identify some pathing errors.

### diskfree.isErrDenied(error):

Returns `true` if the errorcode is one of the windows/unix errorcodes that indicate permission was denied

Note: this might only identify some permission errors.

### diskfree.isErrIO(error):

Returns `true` if the errorcode is one of the windows/unix errorcodes that indicate there was an io error

Note: this might only identify some IO errors.



## Testing

To test just the base C code, run the `test.exe`

``` bash
make test-c
```

To run the node test
``` bash
make test-js
```



## Compiling


To compile just the C code run the following

``` bash
make
```

Reminder: You need make on windows, in MingW you need to adds it binary path `/c/MingW/bin/mingw32-make.exe`



## License

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/Saevon/node-diskfree/blob/master/LICENSE)

---
_Source: https://npm.io/package/diskfree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
