summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_fs/_fs_statfs.js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-03-13 10:57:59 +0000
committerGitHub <noreply@github.com>2024-03-13 10:57:59 +0000
commitf377fce640002c687bb2f36918f857fcc2f7bc7b (patch)
tree2192831a7a9328e8fb1030fc0e127ac841e73024 /ext/node/polyfills/_fs/_fs_statfs.js
parent5cfa03ceca396b1c21a826cb44a984329cf35078 (diff)
feat(node): implement fs.statfs() (#22862)
Diffstat (limited to 'ext/node/polyfills/_fs/_fs_statfs.js')
-rw-r--r--ext/node/polyfills/_fs/_fs_statfs.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/node/polyfills/_fs/_fs_statfs.js b/ext/node/polyfills/_fs/_fs_statfs.js
new file mode 100644
index 000000000..51da1ed68
--- /dev/null
+++ b/ext/node/polyfills/_fs/_fs_statfs.js
@@ -0,0 +1,56 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { BigInt } from "ext:deno_node/internal/primordials.mjs";
+import { op_node_statfs } from "ext:core/ops";
+import { promisify } from "ext:deno_node/internal/util.mjs";
+
+class StatFs {
+ type;
+ bsize;
+ blocks;
+ bfree;
+ bavail;
+ files;
+ ffree;
+ constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
+ this.type = type;
+ this.bsize = bsize;
+ this.blocks = blocks;
+ this.bfree = bfree;
+ this.bavail = bavail;
+ this.files = files;
+ this.ffree = ffree;
+ }
+}
+
+export function statfs(path, options, callback) {
+ if (typeof options === "function") {
+ callback = options;
+ options = {};
+ }
+ try {
+ const res = statfsSync(path, options);
+ callback(null, res);
+ } catch (err) {
+ callback(err, null);
+ }
+}
+
+export function statfsSync(path, options) {
+ const bigint = typeof options?.bigint === "boolean" ? options.bigint : false;
+ const statFs = op_node_statfs(
+ path,
+ bigint,
+ );
+ return new StatFs(
+ bigint ? BigInt(statFs.type) : statFs.type,
+ bigint ? BigInt(statFs.bsize) : statFs.bsize,
+ bigint ? BigInt(statFs.blocks) : statFs.blocks,
+ bigint ? BigInt(statFs.bfree) : statFs.bfree,
+ bigint ? BigInt(statFs.bavail) : statFs.bavail,
+ bigint ? BigInt(statFs.files) : statFs.files,
+ bigint ? BigInt(statFs.ffree) : statFs.ffree,
+ );
+}
+
+export const statfsPromise = promisify(statfs);