Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update documentation in fs.StatsFs #54309

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Example:**

```javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```javascript
```mjs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please verify all the changes?

import { statfs } from "fs/promises";

async function getAvailableSpace(path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of simplicity, isn't it better to use top level await instead of an async function?

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:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Example:**

```javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```javascript
```mjs

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:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Example:**

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please verify the changes?

```javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```javascript
```mjs

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```javascript
```mjs

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
Loading