Skip to content

Commit 3bd562c

Browse files
committed
doc: update documentation in fs.StatsFs
1 parent 37f9eca commit 3bd562c

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

doc/api/fs.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,6 +7509,19 @@ added:
75097509
75107510
Free blocks available to unprivileged users.
75117511
7512+
**Example:**
7513+
```javascript
7514+
import { statfs } from "fs/promises";
7515+
7516+
async function getAvailableSpace(path) {
7517+
const stats = await statfs(path);
7518+
const availableSpace = stats.bsize * stats.bavail; // available space in bytes
7519+
console.log(`Available space: ${availableSpace} bytes`);
7520+
}
7521+
7522+
getAvailableSpace("/tmp");
7523+
```
7524+
75127525
#### `statfs.bfree`
75137526
75147527
<!-- YAML
@@ -7521,6 +7534,19 @@ added:
75217534
75227535
Free blocks in file system.
75237536
7537+
**Example:**
7538+
```javascript
7539+
import { statfs } from "fs/promises";
7540+
7541+
async function getFreeSpace(path) {
7542+
const stats = await statfs(path);
7543+
const freeSpace = stats.bsize * stats.bfree; // free space in bytes
7544+
console.log(`Free space: ${freeSpace} bytes`);
7545+
}
7546+
7547+
getFreeSpace("/tmp");
7548+
```
7549+
75247550
#### `statfs.blocks`
75257551
75267552
<!-- YAML
@@ -7533,6 +7559,18 @@ added:
75337559
75347560
Total data blocks in file system.
75357561
7562+
**Example:**
7563+
```javascript
7564+
import { statfs } from "fs/promises";
7565+
7566+
async function getTotalBlocks(path) {
7567+
const stats = await statfs(path);
7568+
console.log(`Total blocks: ${stats.blocks}`);
7569+
}
7570+
7571+
getTotalBlocks("/tmp");
7572+
```
7573+
75367574
#### `statfs.bsize`
75377575
75387576
<!-- YAML
@@ -7543,7 +7581,7 @@ added:
75437581
75447582
* {number|bigint}
75457583
7546-
Optimal transfer block size.
7584+
Optimal transfer block size in bytes.
75477585
75487586
#### `statfs.ffree`
75497587
@@ -7569,6 +7607,17 @@ added:
75697607
75707608
Total file nodes in file system.
75717609
7610+
```javascript
7611+
import { statfs } from "fs/promises";
7612+
7613+
async function getTotalFiles(path) {
7614+
const stats = await statfs(path);
7615+
console.log(`Total file nodes: ${stats.files}`);
7616+
}
7617+
7618+
getTotalFiles("/tmp");
7619+
```
7620+
75727621
#### `statfs.type`
75737622
75747623
<!-- YAML
@@ -7579,7 +7628,8 @@ added:
75797628
75807629
* {number|bigint}
75817630
7582-
Type of file system.
7631+
Type of file system.
7632+
This numeric value represents the file system type (e.g., EXT4, NTFS, etc.). The specific value can be interpreted by referring to platform-specific documentation or using a lookup table.
75837633
75847634
### Class: `fs.WriteStream`
75857635

0 commit comments

Comments
 (0)