From 07500241baadb17bf9ab1b4f802c6873a9373fd1 Mon Sep 17 00:00:00 2001 From: shrenisc Date: Sat, 5 Oct 2024 17:44:38 +0530 Subject: [PATCH 1/7] doc: updated the Class:fs filesystem documentation as it was missing information and examples Defined the return type for statfs.bsize. Added examples for statfs.bavail, statfs.bfree, statfs.blocks and statfs.files for clarity. Cleared the air on why statfs.type returns a int|bigint value. Fixes: https://github.com/nodejs/node/issues/50749 --- doc/api/fs.md | 167 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 374e51434d78a2..f86292a7bf3cf3 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -7510,6 +7510,24 @@ added: Free blocks available to unprivileged users. +Example: +```mjs +const fs = require('fs'); + +// Specify the path you want to check (like '/' or 'C:/'). +fs.statfs('.', (err, stats) => { + if (err) { + console.error('Error reading file system stats:', err); + return; + } + + // Calculate available space in bytes + const availableSpace = stats.bavail * stats.bsize; + + console.log(`Available space for unprivileged users: ${availableSpace} bytes`); +}); +``` + #### `statfs.bfree`