diff options
Diffstat (limited to 'ext/node/polyfills')
-rw-r--r-- | ext/node/polyfills/_fs/_fs_statfs.js | 56 | ||||
-rw-r--r-- | ext/node/polyfills/fs.ts | 10 | ||||
-rw-r--r-- | ext/node/polyfills/internal/primordials.mjs | 1 |
3 files changed, 67 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); diff --git a/ext/node/polyfills/fs.ts b/ext/node/polyfills/fs.ts index bf43dd92e..bdf7e4aa6 100644 --- a/ext/node/polyfills/fs.ts +++ b/ext/node/polyfills/fs.ts @@ -76,6 +76,11 @@ import { statSync, } from "ext:deno_node/_fs/_fs_stat.ts"; import { + statfs, + statfsPromise, + statfsSync, +} from "ext:deno_node/_fs/_fs_statfs.js"; +import { symlink, symlinkPromise, symlinkSync, @@ -156,6 +161,7 @@ const promises = { symlink: symlinkPromise, lstat: lstatPromise, stat: statPromise, + statfs: statfsPromise, link: linkPromise, unlink: unlinkPromise, chmod: chmodPromise, @@ -253,6 +259,8 @@ export default { stat, Stats, statSync, + statfs, + statfsSync, symlink, symlinkSync, truncate, @@ -354,6 +362,8 @@ export { rmdirSync, rmSync, stat, + statfs, + statfsSync, Stats, statSync, symlink, diff --git a/ext/node/polyfills/internal/primordials.mjs b/ext/node/polyfills/internal/primordials.mjs index d3726cf45..f1e775bc5 100644 --- a/ext/node/polyfills/internal/primordials.mjs +++ b/ext/node/polyfills/internal/primordials.mjs @@ -12,6 +12,7 @@ export const ArrayPrototypeSlice = (that, ...args) => that.slice(...args); export const ArrayPrototypeSome = (that, ...args) => that.some(...args); export const ArrayPrototypeSort = (that, ...args) => that.sort(...args); export const ArrayPrototypeUnshift = (that, ...args) => that.unshift(...args); +export const BigInt = globalThis.BigInt; export const ObjectAssign = Object.assign; export const ObjectCreate = Object.create; export const ObjectHasOwn = Object.hasOwn; |