Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js stats.blksize Property from fs.Stats Class

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The stats.blksize property is an inbuilt application programming interface of the fs.Stats class is used to get the block size for I/O operations in the file system in bytes.

Syntax:

stats.blksize;

Return Value: It returns a number or BigInt value which represents the block size for I/O operations in the file system in bytes.

Below examples illustrate the use of stats.blksize in Node.js:

Example 1:




// Node.js program to demonstrate the   
// stats.blksize property
  
// Accessing fs module
const fs = require('fs');
  
// Calling fs.Stats stats.blksize
// using stat
fs.stat('./', (err, stats) => {
  if (err) throw err;
  console.log("using stat: the block "
    + "size for I/O operations in the"
    + " file system in bytes is "
    + stats.blksize);
});
   
// Using lstat
fs.lstat('./', (err, stats) => {
  if (err) throw err;
  console.log("using lstat: the block "
    + "size for I/O operations in the "
    + "file system in bytes is "
    + stats.blksize);
});

Output:

using stat: the block size for I/O operations 
in the file in bytes is  4096
using lstat: the block size for I/O operations 
in the file in bytes is  4096

Example 2:




// Node.js program to demonstrate the   
// stats.blksize property
  
// Accessing fs module
const fs = require('fs').promises;
  
// Calling fs.Stats stats.blksize
(async () => {
    const stats = await fs.stat('./');
    console.log("using stat synchronous: "
        + "the block size for I/O operations"
        + " in the file system in bytes is " 
        + stats.blksize);
})().catch(console.error)

Output:

(node:6376) ExperimentalWarning: The fs.promises
API is experimental
using stat synchronous: the block size for I/O 
operations in the file system in bytes is  4096

Note: The above program will compile and run by using the node filename.js command and use the file_path correctly.

Reference: https://nodejs.org/api/fs.html#fs_stats_blksize


My Personal Notes arrow_drop_up
Last Updated : 26 Jun, 2020
Like Article
Save Article
Similar Reads
Related Tutorials