Skip to content
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
Next Next commit
doc: update documentation in fs.StatsFs
  • Loading branch information
Codder-lab committed Aug 11, 2024
commit 3bd562cf9fe0b2798b54850b321cc35be6bc28ae
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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