diff --git a/doc/api/fs.md b/doc/api/fs.md index 94aea1032f539c..138d87218794f2 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -7926,6 +7926,35 @@ StatFs { } ``` +To calculate disk space from a `StatFs` object, multiply the block count +properties by the fundamental block size (`statfs.frsize`) to convert +them to bytes. Pass `{ bigint: true }` to avoid loss of precision on +large file systems: + +```mjs +import { statfs } from 'node:fs/promises'; + +const stats = await statfs('/', { bigint: true }); +const blockSize = stats.frsize; + +console.log(`Total: ${stats.blocks * blockSize} bytes`); +console.log(`Free: ${stats.bfree * blockSize} bytes`); +console.log(`Available: ${stats.bavail * blockSize} bytes`); +``` + +```cjs +const { statfs } = require('node:fs'); + +statfs('/', { bigint: true }, (err, stats) => { + if (err) throw err; + const blockSize = stats.frsize; + + console.log(`Total: ${stats.blocks * blockSize} bytes`); + console.log(`Free: ${stats.bfree * blockSize} bytes`); + console.log(`Available: ${stats.bavail * blockSize} bytes`); +}); +``` + #### `statfs.bavail`