来自 fs.Stats 类的 Node.js stats.blksize 属性
stats.blksize 属性是 fs.Stats 类的内置应用程序编程接口,用于获取文件系统中 I/O 操作的块大小(以字节为单位)。
句法:
stats.blksize;
返回值:它返回一个数字或 BigInt 值,表示文件系统中 I/O 操作的块大小(以字节为单位)。
以下示例说明了 Node.js 中 stats.blksize 的使用:
示例 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);
});
输出:
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
示例 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)
输出:
(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
注意:以上程序将通过使用node filename.js
命令编译运行,并正确使用 file_path。
参考: https://nodejs.org/api/fs.html#fs_stats_blksize