Getting free disk space without using child_process.
Hello everyone!
I would like to create a small CLI tool using Typescript and Deno. I would like to monitor the free disk space on several disks.
How can I get the free disk space on a Linux machine without forking a separate process (like
exec --> df
and the like)?
In addition, I would like to deno compile
my little program later, so I am not sure if Node's gyp is an option then.6 Replies
I don't think deno runtime exposés this
I would just strace df to see how it does it, it probably boils down to a Linux syscall since it finishes immediately
In that case you'll need ffi
I found a npm packae doing exactly that but it's based on gyp. can i somehow "convert" that? or is deno gyp compatible?
No, there is no equivalent to gyp in Deno
Maybe there is some WASM implementation out there for this.
ok, thanks.
the program needs to issue statfs syscall, you can't do that in a javascript runtime, your options is to either run df or bind to a library with ffi that does this , i think both options are equivalent really
If you want to see an implementation example, you can checkout https://github.com/uutils/coreutils/tree/main/src/uu/df (its also crossplatform)
Also here is the simplest program in rust (for linux)
Thanks a bunch! I figured it out basing my code on the FFI examples and the diskusage npm package.