https://github.com/brettchalupa/deno_disk_usage
Function for Deno to get usage of a given disk; requires the `df` bin to be installed.
https://github.com/brettchalupa/deno_disk_usage
deno jsr
Last synced: about 2 months ago
JSON representation
Function for Deno to get usage of a given disk; requires the `df` bin to be installed.
- Host: GitHub
- URL: https://github.com/brettchalupa/deno_disk_usage
- Owner: brettchalupa
- License: unlicense
- Created: 2024-12-22T03:18:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-22T03:54:05.000Z (over 1 year ago)
- Last Synced: 2025-04-09T09:16:57.505Z (about 1 year ago)
- Topics: deno, jsr
- Language: TypeScript
- Homepage: https://jsr.io/@brettchalupa/deno-disk-usage
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deno Disk Usage
A simple program and function to determine disk usage from a Deno program.
Deno does not include anything in its stdlib that returns disk size, usage, and
free space. So this parses out the results of the `df` command, which is wildly
available on \*nix systems.
It's unclear how precise the data is (as in I never heard of a mebibyte before
writing this code), but it's good enough for some simple checking and
monitoring.
Ideally Deno would include this data like it does for CPU and RAM. Another
option could be to try to use the Rust
[sysinfo](https://crates.io/crates/sysinfo) crate to get these details.
## Run
On macOS, here's how this could be used:
```
deno run --allow-run jsr:@brettchalupa/deno-disk-usage/cli /System/Volumes/Data
```
You can pass multiple disks in as separate args.
Which outputs:
```console
/System/Volumes/Data disk usage: 66 %
/System/Volumes/Data used: 290010 MB
/System/Volumes/Data used: 471482 MB
```
## Use the Function
Drop the `DiskUsage` interface and the `getDiskUsage()` function into your
project and then call it:
```ts
import { getDiskUsage } from "jsr:@brettchalupa/deno-disk-usage";
const diskUsage = await getDiskUsage();
console.log(`${diskUsage.percentageUsed}% of ${diskUage.path} disk used`);
```
Or add it to your Deno project with:
```
deno add jsr:@brettchalupa/deno-disk-usage
```
And import it with:
```ts
import { getDiskUsage } from "@brettchalupa/deno-disk-usage";
```
## License
Unlicense - Public Domain
---
## Dev Notes
New versions are automatically published when code is pushed to `main` with a
bumped `version` in `deno.json`.