Skip to content

Commit

Permalink
doc: update documentation in fs.StatsFs
Browse files Browse the repository at this point in the history
  • Loading branch information
Codder-lab committed Aug 11, 2024
1 parent 37f9eca commit 3bd562c
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7509,6 +7509,19 @@ added:
Free blocks available to unprivileged users.
**Example:**
```javascript
import { statfs } from "fs/promises";

async function getAvailableSpace(path) {
const stats = await statfs(path);
const availableSpace = stats.bsize * stats.bavail; // available space in bytes
console.log(`Available space: ${availableSpace} bytes`);
}

getAvailableSpace("/tmp");
```
#### `statfs.bfree`
<!-- YAML
Expand All @@ -7521,6 +7534,19 @@ added:
Free blocks in file system.
**Example:**
```javascript
import { statfs } from "fs/promises";

async function getFreeSpace(path) {
const stats = await statfs(path);
const freeSpace = stats.bsize * stats.bfree; // free space in bytes
console.log(`Free space: ${freeSpace} bytes`);
}

getFreeSpace("/tmp");
```
#### `statfs.blocks`
<!-- YAML
Expand All @@ -7533,6 +7559,18 @@ added:
Total data blocks in file system.
**Example:**
```javascript
import { statfs } from "fs/promises";

async function getTotalBlocks(path) {
const stats = await statfs(path);
console.log(`Total blocks: ${stats.blocks}`);
}

getTotalBlocks("/tmp");
```
#### `statfs.bsize`
<!-- YAML
Expand All @@ -7543,7 +7581,7 @@ added:
* {number|bigint}
Optimal transfer block size.
Optimal transfer block size in bytes.
#### `statfs.ffree`
Expand All @@ -7569,6 +7607,17 @@ added:
Total file nodes in file system.
```javascript
import { statfs } from "fs/promises";

async function getTotalFiles(path) {
const stats = await statfs(path);
console.log(`Total file nodes: ${stats.files}`);
}

getTotalFiles("/tmp");
```
#### `statfs.type`
<!-- YAML
Expand All @@ -7579,7 +7628,8 @@ added:
* {number|bigint}
Type of file system.
Type of file system.
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.
### Class: `fs.WriteStream`
Expand Down

0 comments on commit 3bd562c

Please sign in to comment.