🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

bare-fs

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-fs - npm Package Compare versions

Comparing version
4.6.0
to
4.7.0
+106
-0
index.d.ts

@@ -119,2 +119,24 @@ import EventEmitter, { EventMap } from 'bare-events'

export interface StatFs {
readonly type: number
readonly bsize: number
readonly blocks: number
readonly bfree: number
readonly bavail: number
readonly files: number
readonly ffree: number
}
export class StatsFs {
private constructor(
type: number,
bsize: number,
blocks: number,
bfree: number,
bavail: number,
files: number,
ffree: number
)
}
export interface ReadStreamOptions {

@@ -251,2 +273,8 @@ fd?: number

export function chown(filepath: Path, uid: number, gid: number): Promise<void>
export function chown(filepath: Path, uid: number, gid: number, cb: Callback): void
export function chownSync(filepath: Path, uid: number, gid: number): void
export function close(fd: number): Promise<void>

@@ -290,2 +318,14 @@

export function fchown(fd: number, uid: number, gid: number): Promise<void>
export function fchown(fd: number, uid: number, gid: number, cb: Callback): void
export function fchownSync(fd: number, uid: number, gid: number): void
export function fdatasync(fd: number): Promise<void>
export function fdatasync(fd: number, cb: Callback): void
export function fdatasyncSync(fd: number): void
export function fstat(fd: number): Promise<Stats>

@@ -297,2 +337,8 @@

export function fsync(fd: number): Promise<void>
export function fsync(fd: number, cb: Callback): void
export function fsyncSync(fd: number): void
export function ftruncate(fd: number, len?: number): Promise<void>

@@ -306,2 +352,8 @@

export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
export function lchown(filepath: Path, uid: number, gid: number, cb: Callback): void
export function lchownSync(filepath: Path, uid: number, gid: number): void
export function lstat(filepath: Path): Promise<Stats>

@@ -313,2 +365,36 @@

export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
export function utimes(
filepath: Path,
atime: number | Date,
mtime: number | Date,
cb: Callback
): void
export function utimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
export function lutimes(
filepath: Path,
atime: number | Date,
mtime: number | Date,
cb: Callback
): void
export function lutimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
export function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void>
export function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: Callback): void
export function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void
export function link(src: Path, dst: Path): Promise<void>
export function link(src: Path, dst: Path, cb: Callback): void
export function linkSync(src: Path, dst: Path): void
export interface MkdirOptions {

@@ -333,2 +419,8 @@ mode?: number

export function mkdtemp(prefix: Path): Promise<string>
export function mkdtemp(prefix: Path, cb: Callback<[path: string | null]>): void
export function mkdtempSync(prefix: Path): string
export function open(filepath: Path, flags?: Flag | number, mode?: string | number): Promise<number>

@@ -945,2 +1037,8 @@

export function statfs(filepath: Path): Promise<StatFs>
export function statfs(filepath: Path, cb: Callback<[stats: StatFs | null]>): void
export function statfsSync(filepath: Path): StatFs
export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>

@@ -954,2 +1052,10 @@

export function truncate(filepath: Path, len?: number): Promise<void>
export function truncate(filepath: Path, len: number, cb: Callback): void
export function truncate(filepath: Path, cb: Callback): void
export function truncateSync(filepath: Path, len?: number): void
export function unlink(filepath: Path): Promise<void>

@@ -956,0 +1062,0 @@

+413
-51

@@ -491,7 +491,3 @@ const FIFO = require('fast-fifo')

} catch (e) {
err = new FileError(e.message, {
operation: 'stat',
code: e.code,
path: filepath
})
err = new FileError(e.message, { operation: 'stat', code: e.code, path: filepath })
} finally {

@@ -514,7 +510,3 @@ req.return()

} catch (e) {
throw new FileError(e.message, {
operation: 'stat',
code: e.code,
path: filepath
})
throw new FileError(e.message, { operation: 'stat', code: e.code, path: filepath })
} finally {

@@ -539,7 +531,3 @@ req.return()

} catch (e) {
err = new FileError(e.message, {
operation: 'lstat',
code: e.code,
path: filepath
})
err = new FileError(e.message, { operation: 'lstat', code: e.code, path: filepath })
} finally {

@@ -562,7 +550,3 @@ req.return()

} catch (e) {
throw new FileError(e.message, {
operation: 'lstat',
code: e.code,
path: filepath
})
throw new FileError(e.message, { operation: 'lstat', code: e.code, path: filepath })
} finally {

@@ -607,2 +591,40 @@ req.return()

async function statfs(filepath, cb) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
let st
let err = null
try {
binding.statfs(req.handle, filepath)
await req
st = new StatFs(...binding.requestResultStatfs(req.handle))
} catch (e) {
err = new FileError(e.message, { operation: 'statfs', code: e.code, path: filepath })
} finally {
req.return()
}
return done(err, st, cb)
}
function statfsSync(filepath) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
try {
binding.statfsSync(req.handle, filepath)
return new StatFs(...binding.requestResultStatfs(req.handle))
} catch (e) {
throw new FileError(e.message, { operation: 'statfs', code: e.code, path: filepath })
} finally {
req.return()
}
}
async function ftruncate(fd, len = 0, cb) {

@@ -646,2 +668,34 @@ if (typeof len === 'function') {

async function truncate(filepath, len, cb) {
let fd = -1
let err
try {
fd = await open(filepath, 'r+')
await ftruncate(fd, len)
} catch (e) {
err = e
} finally {
if (fd !== -1) await close(fd)
}
return done(err, cb)
}
function truncateSync(filepath, len) {
let fd = -1
let err
try {
fd = openSync(filepath, 'r+')
ftruncateSync(fd, len)
} catch (e) {
err = e
} finally {
if (fd !== -1) closeSync(fd)
}
}
async function chmod(filepath, mode, cb) {

@@ -725,2 +779,97 @@ if (typeof mode === 'string') mode = toMode(mode)

async function chown(filepath, uid, gid, cb) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
let err = null
try {
binding.chown(req.handle, filepath, uid, gid)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'chown', code: e.code, path: filepath })
} finally {
req.return()
}
return done(err, cb)
}
function chownSync(filepath, uid, gid) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
try {
binding.chownSync(req.handle, filepath, uid, gid)
} catch (e) {
throw new FileError(e.message, { operation: 'chownSync', code: e.code, path: filepath })
} finally {
req.return()
}
}
async function lchown(filepath, uid, gid, cb) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
let err = null
try {
binding.lchown(req.handle, filepath, uid, gid)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'lchown', code: e.code, path: filepath })
} finally {
req.return()
}
return done(err, cb)
}
function lchownSync(filepath, uid, gid) {
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
try {
binding.lchownSync(req.handle, filepath, uid, gid)
} catch (e) {
throw new FileError(e.message, { operation: 'lchownSync', code: e.code, path: filepath })
} finally {
req.return()
}
}
async function fchown(fd, uid, gid, cb) {
const req = FileRequest.borrow()
let err = null
try {
binding.fchown(req.handle, fd, uid, gid)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'fchown', code: e.code, fd })
} finally {
req.return()
}
return done(err, cb)
}
function fchownSync(fd, uid, gid) {
const req = FileRequest.borrow()
try {
binding.fchownSync(req.handle, fd, uid, gid)
} catch (e) {
throw new FileError(e.message, { operation: 'fchownSync', code: e.code, fd })
} finally {
req.return()
}
}
async function utimes(filepath, atime, mtime, cb) {

@@ -740,7 +889,3 @@ if (typeof atime !== 'number') atime = atime.getTime() / 1000

} catch (e) {
err = new FileError(e.message, {
operation: 'utimes',
code: e.code,
path: filepath
})
err = new FileError(e.message, { operation: 'utimes', code: e.code, path: filepath })
} finally {

@@ -764,6 +909,116 @@ req.return()

} catch (e) {
throw new FileError(e.message, { operation: 'utimes', code: e.code, path: filepath })
} finally {
req.return()
}
}
async function lutimes(filepath, atime, mtime, cb) {
if (typeof atime !== 'number') atime = atime.getTime() / 1000
if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
let err = null
try {
binding.lutimes(req.handle, filepath, atime, mtime)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'lutimes', code: e.code, path: filepath })
} finally {
req.return()
}
return done(err, cb)
}
function lutimesSync(filepath, atime, mtime) {
if (typeof atime !== 'number') atime = atime.getTime() / 1000
if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
filepath = toNamespacedPath(filepath)
const req = FileRequest.borrow()
try {
binding.lutimesSync(req.handle, filepath, atime, mtime)
} catch (e) {
throw new FileError(e.message, { operation: 'lutimes', code: e.code, path: filepath })
} finally {
req.return()
}
}
async function futimes(fd, atime, mtime, cb) {
if (typeof atime !== 'number') atime = atime.getTime() / 1000
if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
const req = FileRequest.borrow()
let err = null
try {
binding.futimes(req.handle, fd, atime, mtime)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'futimes', code: e.code, fd })
} finally {
req.return()
}
return done(err, cb)
}
function futimesSync(fd, atime, mtime) {
if (typeof atime !== 'number') atime = atime.getTime() / 1000
if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
const req = FileRequest.borrow()
try {
binding.futimesSync(req.handle, fd, atime, mtime)
} catch (e) {
throw new FileError(e.message, { operation: 'futimesSync', code: e.code, fd })
} finally {
req.return()
}
}
async function link(src, dst, cb) {
src = toNamespacedPath(src)
dst = toNamespacedPath(dst)
const req = FileRequest.borrow()
let err = null
try {
binding.link(req.handle, src, dst)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'link', code: e.code, path: src, destination: dst })
} finally {
req.return()
}
return done(err, cb)
}
function linkSync(src, dst) {
src = toNamespacedPath(src)
dst = toNamespacedPath(dst)
const req = FileRequest.borrow()
try {
binding.linkSync(req.handle, src, dst)
} catch (e) {
throw new FileError(e.message, {
operation: 'utimes',
operation: 'linkSync',
code: e.code,
path: filepath
path: src,
destination: dst
})

@@ -884,2 +1139,40 @@ } finally {

async function mkdtemp(prefix, cb) {
prefix = toNamespacedPath(prefix)
const req = FileRequest.borrow()
let res
let err = null
try {
binding.mkdtemp(req.handle, prefix + 'XXXXXX')
await req
res = binding.requestResultPath(req.handle)
} catch (e) {
err = new FileError(e.message, { operation: 'mkdtemp', code: e.code, path: prefix })
} finally {
req.return()
}
return done(err, res, cb)
}
function mkdtempSync(prefix) {
prefix = toNamespacedPath(prefix)
const req = FileRequest.borrow()
try {
binding.mkdtempSync(req.handle, prefix + 'XXXXXX')
return binding.requestResultPath(req.handle)
} catch (e) {
throw new FileError(e.message, { operation: 'mkdtempSync', code: e.code, path: prefix })
} finally {
req.return()
}
}
async function rmdir(filepath, cb) {

@@ -1352,2 +1645,60 @@ filepath = toNamespacedPath(filepath)

async function fsync(fd, cb) {
const req = FileRequest.borrow()
let err = null
try {
binding.fsync(req.handle, fd)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'fsync', code: e.code, fd })
} finally {
req.return()
}
return done(err, cb)
}
function fsyncSync(fd) {
const req = FileRequest.borrow()
try {
binding.fsyncSync(req.handle, fd)
} catch (e) {
throw new FileError(e.message, { operation: 'fsyncSync', code: e.code, fd })
} finally {
req.return()
}
}
async function fdatasync(fd, cb) {
const req = FileRequest.borrow()
let err = null
try {
binding.fdatasync(req.handle, fd)
await req
} catch (e) {
err = new FileError(e.message, { operation: 'fdatasync', code: e.code, fd })
} finally {
req.return()
}
return done(err, cb)
}
function fdatasyncSync(fd) {
const req = FileRequest.borrow()
try {
binding.fdatasyncSync(req.handle, fd)
} catch (e) {
throw new FileError(e.message, { operation: 'fdatasyncSync', code: e.code, fd })
} finally {
req.return()
}
}
function normalizeSymlinkTarget(target, type, filepath) {

@@ -1835,2 +2186,14 @@ if (isWindows) {

class StatFs {
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
}
}
class Dir {

@@ -2300,3 +2663,3 @@ constructor(path, handle, opts = {}) {

exports.chmod = chmod
// exports.chown = chown TODO
exports.chown = chown
exports.close = close

@@ -2307,15 +2670,14 @@ exports.copyFile = copyFile

exports.fchmod = fchmod
// exports.fchown = fchown TODO
// exports.fdatasync = fdatasync TODO
exports.fchown = fchown
exports.fdatasync = fdatasync
exports.fstat = fstat
// exports.fsync = fsync TODO
exports.fsync = fsync
exports.ftruncate = ftruncate
// exports.futimes = futimes TODO
// exports.lchmod = lchmod TODO
// exports.lchown = lchown TODO
// exports.lutimes = lutimes TODO
// exports.link = link TODO
exports.futimes = futimes
exports.lchown = lchown
exports.lutimes = lutimes
exports.link = link
exports.lstat = lstat
exports.mkdir = mkdir
// exports.mkdtemp = mkdtemp TODO
exports.mkdtemp = mkdtemp
exports.open = open

@@ -2333,5 +2695,5 @@ exports.opendir = opendir

exports.stat = stat
// exports.statfs = statfs TODO
exports.statfs = statfs
exports.symlink = symlink
// exports.truncate = truncate TODO
exports.truncate = truncate
exports.unlink = unlink

@@ -2347,3 +2709,3 @@ exports.utimes = utimes

exports.chmodSync = chmodSync
// exports.chownSync = chownSync TODO
exports.chownSync = chownSync
exports.closeSync = closeSync

@@ -2354,15 +2716,14 @@ exports.copyFileSync = copyFileSync

exports.fchmodSync = fchmodSync
// exports.fchownSync = fchownSync TODO
// exports.fdatasyncSync = fdatasyncSync TODO
exports.fchownSync = fchownSync
exports.fdatasyncSync = fdatasyncSync
exports.fstatSync = fstatSync
// exports.fsyncSync = fsyncSync TODO
exports.fsyncSync = fsyncSync
exports.ftruncateSync = ftruncateSync
// exports.futimesSync = futimesSync TODO
// exports.lchmodSync = lchmodSync TODO
// exports.lchownSync = lchownSync TODO
// exports.lutimesSync = lutimesSync TODO
// exports.linkSync = linkSync TODO
exports.futimesSync = futimesSync
exports.lchownSync = lchownSync
exports.lutimesSync = lutimesSync
exports.linkSync = linkSync
exports.lstatSync = lstatSync
exports.mkdirSync = mkdirSync
// exports.mkdtempSync = mkdtempSync TODO
exports.mkdtempSync = mkdtempSync
exports.openSync = openSync

@@ -2380,5 +2741,5 @@ exports.opendirSync = opendirSync

exports.statSync = statSync
// exports.statfsSync = statfsSync TODO
exports.statfsSync = statfsSync
exports.symlinkSync = symlinkSync
// exports.truncateSync = truncateSync TODO
exports.truncateSync = truncateSync
exports.unlinkSync = unlinkSync

@@ -2393,2 +2754,3 @@ exports.utimesSync = utimesSync

exports.Stats = Stats
exports.StatFs = StatFs
exports.Dir = Dir

@@ -2395,0 +2757,0 @@ exports.Dirent = Dirent

+2
-2
{
"name": "bare-fs",
"version": "4.6.0",
"description": "Native file system operations for Javascript",
"version": "4.7.0",
"description": "Native file system operations for Bare",
"exports": {

@@ -6,0 +6,0 @@ "./package": "./package.json",

@@ -33,2 +33,4 @@ import EventEmitter, { EventMap } from 'bare-events'

interface FileHandle extends EventEmitter<FileHandleEvents>, AsyncDisposable {
readonly fd: number
close(): Promise<void>

@@ -58,2 +60,12 @@

chown(uid: number, gid: number): Promise<void>
datasync(): Promise<void>
sync(): Promise<void>
truncate(len?: number): Promise<void>
utimes(atime: number | Date, mtime: number | Date): Promise<void>
createReadStream(opts?: ReadStreamOptions): ReadStream

@@ -90,2 +102,4 @@

export function chown(filepath: Path, uid: number, gid: number): Promise<void>
export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>

@@ -95,2 +109,8 @@

export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
export function link(src: Path, dst: Path): Promise<void>
export function lstat(filepath: Path): Promise<Stats>

@@ -102,2 +122,4 @@

export function mkdtemp(prefix: Path): Promise<string>
export function opendir(

@@ -253,2 +275,6 @@ filepath: Path,

export function statfs(filepath: Path): Promise<StatFs>
export function truncate(filepath: Path, len?: number): Promise<void>
export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>

@@ -258,2 +284,4 @@

export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
export function watch(

@@ -260,0 +288,0 @@ filepath: Path,

@@ -54,2 +54,22 @@ const EventEmitter = require('bare-events')

async chown(uid, gid) {
await fs.fchown(this.fd, uid, gid)
}
async datasync() {
return fs.fdatasync(this.fd)
}
async sync() {
return fs.fsync(this.fd)
}
async truncate(len) {
await fs.ftruncate(this.fd, len)
}
async utimes(atime, mtime) {
await fs.futimes(this.fd, atime, mtime)
}
createReadStream(opts) {

@@ -75,7 +95,12 @@ return fs.createReadStream(null, { ...opts, fd: this.fd })

exports.chmod = fs.chmod
exports.chown = fs.chown
exports.constants = fs.constants
exports.copyFile = fs.copyFile
exports.cp = fs.cp
exports.lchown = fs.lchown
exports.lutimes = fs.lutimes
exports.link = fs.link
exports.lstat = fs.lstat
exports.mkdir = fs.mkdir
exports.mkdtemp = fs.mkdtemp
exports.opendir = fs.opendir

@@ -90,2 +115,4 @@ exports.readFile = fs.readFile

exports.stat = fs.stat
exports.statfs = fs.statfs
exports.truncate = fs.truncate
exports.symlink = fs.symlink

@@ -92,0 +119,0 @@ exports.unlink = fs.unlink

+960
-1
# bare-fs
Native file system operations for Javascript.
Native file system operations for Bare. The API closely follows that of the Node.js `fs` module.

@@ -27,4 +27,963 @@ ```

## API
#### `const fd = await fs.open(filepath[, flags[, mode]])`
Open a file, returning a file descriptor. `flags` defaults to `'r'` and `mode` defaults to `0o666`. `flags` may be a string such as `'r'`, `'w'`, `'a'`, `'r+'`, etc., or a numeric combination of `fs.constants` flags.
#### `fs.open(filepath[, flags[, mode]], callback)`
Callback version of `fs.open()`.
#### `const fd = fs.openSync(filepath[, flags[, mode]])`
Synchronous version of `fs.open()`.
#### `await fs.close(fd)`
Close a file descriptor.
#### `fs.close(fd, callback)`
Callback version of `fs.close()`.
#### `fs.closeSync(fd)`
Synchronous version of `fs.close()`.
#### `await fs.access(filepath[, mode])`
Check whether the file at `filepath` is accessible. `mode` defaults to `fs.constants.F_OK`.
#### `fs.access(filepath[, mode], callback)`
Callback version of `fs.access()`.
#### `fs.accessSync(filepath[, mode])`
Synchronous version of `fs.access()`.
#### `const exists = await fs.exists(filepath)`
Check whether a file exists at `filepath`. Returns `true` if the file is accessible, `false` otherwise.
#### `fs.exists(filepath, callback)`
Callback version of `fs.exists()`.
#### `const exists = fs.existsSync(filepath)`
Synchronous version of `fs.exists()`.
#### `const bytesRead = await fs.read(fd, buffer[, offset[, len[, pos]]])`
Read from a file descriptor into `buffer`. `offset` defaults to `0`, `len` defaults to `buffer.byteLength - offset`, and `pos` defaults to `-1` (current position). Returns the number of bytes read.
#### `fs.read(fd, buffer[, offset[, len[, pos]]], callback)`
Callback version of `fs.read()`.
#### `const bytesRead = fs.readSync(fd, buffer[, offset[, len[, pos]]])`
Synchronous version of `fs.read()`.
#### `const bytesRead = await fs.readv(fd, buffers[, pos])`
Read from a file descriptor into an array of `buffers`. `pos` defaults to `-1`.
#### `fs.readv(fd, buffers[, pos], callback)`
Callback version of `fs.readv()`.
#### `const bytesRead = fs.readvSync(fd, buffers[, pos])`
Synchronous version of `fs.readv()`.
#### `const bytesWritten = await fs.write(fd, data[, offset[, len[, pos]]])`
Write `data` to a file descriptor. When `data` is a string, the signature is `fs.write(fd, data[, pos[, encoding]])` where `encoding` defaults to `'utf8'`. Returns the number of bytes written.
#### `fs.write(fd, data[, offset[, len[, pos]]], callback)`
Callback version of `fs.write()`.
#### `const bytesWritten = fs.writeSync(fd, data[, offset[, len[, pos]]])`
Synchronous version of `fs.write()`.
#### `const bytesWritten = await fs.writev(fd, buffers[, pos])`
Write an array of `buffers` to a file descriptor. `pos` defaults to `-1`.
#### `fs.writev(fd, buffers[, pos], callback)`
Callback version of `fs.writev()`.
#### `const bytesWritten = fs.writevSync(fd, buffers[, pos])`
Synchronous version of `fs.writev()`.
#### `const stats = await fs.stat(filepath)`
Get the status of a file. Returns a `Stats` object.
#### `fs.stat(filepath, callback)`
Callback version of `fs.stat()`.
#### `const stats = fs.statSync(filepath)`
Synchronous version of `fs.stat()`.
#### `const stats = await fs.lstat(filepath)`
Like `fs.stat()`, but if `filepath` is a symbolic link, the link itself is statted, not the file it refers to.
#### `fs.lstat(filepath, callback)`
Callback version of `fs.lstat()`.
#### `const stats = fs.lstatSync(filepath)`
Synchronous version of `fs.lstat()`.
#### `const stats = await fs.fstat(fd)`
Get the status of a file by its file descriptor. Returns a `Stats` object.
#### `fs.fstat(fd, callback)`
Callback version of `fs.fstat()`.
#### `const stats = fs.fstatSync(fd)`
Synchronous version of `fs.fstat()`.
#### `const stats = await fs.statfs(filepath)`
Get filesystem statistics. Returns a `StatFs` object.
#### `fs.statfs(filepath, callback)`
Callback version of `fs.statfs()`.
#### `const stats = fs.statfsSync(filepath)`
Synchronous version of `fs.statfs()`.
#### `await fs.ftruncate(fd[, len])`
Truncate a file to `len` bytes. `len` defaults to `0`.
#### `fs.ftruncate(fd[, len], callback)`
Callback version of `fs.ftruncate()`.
#### `fs.ftruncateSync(fd[, len])`
Synchronous version of `fs.ftruncate()`.
#### `await fs.chmod(filepath, mode)`
Change the permissions of a file. `mode` may be a numeric mode or a string that will be parsed as octal.
#### `fs.chmod(filepath, mode, callback)`
Callback version of `fs.chmod()`.
#### `fs.chmodSync(filepath, mode)`
Synchronous version of `fs.chmod()`.
#### `await fs.fchmod(fd, mode)`
Change the permissions of a file by its file descriptor.
#### `fs.fchmod(fd, mode, callback)`
Callback version of `fs.fchmod()`.
#### `fs.fchmodSync(fd, mode)`
Synchronous version of `fs.fchmod()`.
#### `await fs.chown(filepath, uid, gid)`
Change the owner and group of a file.
**NOTE**: The `chown` functions are not implemented on Windows.
#### `fs.chown(filepath, uid, gid, callback)`
Callback version of `fs.chown()`.
#### `await fs.chownSync(filepath, uid, gid)`
Synchronous version of `fs.chown()`.
#### `await fs.lchown(filepath, uid, gid)`
Change the owner and group of a file, but if `filepath` is a symbolic link, the changes are applied only to the link, not the file it refers to.
#### `fs.lchown(filepath, uid, gid, callback)`
Callback version of `fs.lchown()`.
#### `fs.lchownSync(filepath, uid, gid)`
Synchronous version of `fs.lchown()`.
#### `await fs.fchown(filepath, uid, gid)`
Change the owner and group of a file by its file descriptor.
#### `fs.fchown(filepath, uid, gid, callback)`
Callback version of `fs.fchown()`.
#### `fs.fchownSync(filepath, uid, gid)`
Synchronous version of `fs.fchown()`.
#### `await fs.utimes(filepath, atime, mtime)`
Change the access and modification times of a file. Times may be numbers (seconds since epoch) or `Date` objects.
#### `fs.utimes(filepath, atime, mtime, callback)`
Callback version of `fs.utimes()`.
#### `fs.utimesSync(filepath, atime, mtime)`
Synchronous version of `fs.utimes()`.
#### `await fs.lutimes(filepath, atime, mtime)`
Like `fs.utimes()`, but if `filepath` is a symbolic link, the timestamps of the link is changed, not the file it refers to.
#### `fs.lutimes(filepath, atime, mtime, callback)`
Callback version of `fs.lutimes()`.
#### `fs.lutimesSync(filepath, atime, mtime)`
Synchronous version of `fs.lutimes()`.
#### `await fs.futimes(fd, atime, mtime)`
Change the access and modification times of a file by its file descriptor. Times may be numbers (seconds since epoch) or `Date` objects.
#### `fs.futimes(fd, atime, mtime, callback)`
Callback version of `fs.futimes()`.
#### `fs.futimesSync(fd, atime, mtime)`
Synchronous version of `fs.futimes()`.
#### `await fs.link(src, dst)`
Creates a new link (also known as a hard link) to an existing file.
#### `fs.link(src, dst, callback)`
Callback version of `fs.link()`.
#### `fs.linkSync(src, dst)`
Synchronous version of `fs.link()`.
#### `await fs.mkdir(filepath[, opts])`
Create a directory at `filepath`.
Options include:
```js
options = {
mode: 0o777,
recursive: false
}
```
If `opts` is a number, it is treated as the `mode`. When `recursive` is `true`, parent directories are created as needed.
#### `fs.mkdir(filepath[, opts], callback)`
Callback version of `fs.mkdir()`.
#### `fs.mkdirSync(filepath[, opts])`
Synchronous version of `fs.mkdir()`.
#### `const path = await fs.mkdtemp(prefix)`
Create a unique temporary directory.
#### `fs.mkdtemp(prefix, callback)`
Callback version of `fs.mkdtemp()`.
#### `const path = fs.mkdtempSync(prefix)`
Synchronous version of `fs.mkdtemp()`.
#### `await fs.rmdir(filepath)`
Remove an empty directory.
#### `fs.rmdir(filepath, callback)`
Callback version of `fs.rmdir()`.
#### `fs.rmdirSync(filepath)`
Synchronous version of `fs.rmdir()`.
#### `await fs.rm(filepath[, opts])`
Remove a file or directory at `filepath`.
Options include:
```js
options = {
force: false,
recursive: false
}
```
When `recursive` is `true`, directories are removed along with their contents. When `force` is `true`, no error is thrown if `filepath` does not exist.
#### `fs.rm(filepath[, opts], callback)`
Callback version of `fs.rm()`.
#### `fs.rmSync(filepath[, opts])`
Synchronous version of `fs.rm()`.
#### `await fs.unlink(filepath)`
Remove a file.
#### `fs.unlink(filepath, callback)`
Callback version of `fs.unlink()`.
#### `fs.unlinkSync(filepath)`
Synchronous version of `fs.unlink()`.
#### `await fs.rename(src, dst)`
Rename a file from `src` to `dst`.
#### `fs.rename(src, dst, callback)`
Callback version of `fs.rename()`.
#### `fs.renameSync(src, dst)`
Synchronous version of `fs.rename()`.
#### `await fs.copyFile(src, dst[, mode])`
Copy a file from `src` to `dst`. `mode` is an optional bitmask created from `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, or `fs.constants.COPYFILE_FICLONE_FORCE`.
#### `fs.copyFile(src, dst[, mode], callback)`
Callback version of `fs.copyFile()`.
#### `fs.copyFileSync(src, dst[, mode])`
Synchronous version of `fs.copyFile()`.
#### `await fs.cp(src, dst[, opts])`
Copy a file or directory from `src` to `dst`.
Options include:
```js
options = {
recursive: false
}
```
Set `recursive` to `true` to copy directories and their contents. Files are copied preserving their permissions.
#### `fs.cp(src, dst[, opts], callback)`
Callback version of `fs.cp()`.
#### `fs.cpSync(src, dst[, opts])`
Synchronous version of `fs.cp()`.
#### `const resolved = await fs.realpath(filepath[, opts])`
Resolve the real path of `filepath`, expanding all symbolic links.
Options include:
```js
options = {
encoding: 'utf8'
}
```
Set `encoding` to `'buffer'` to receive the result as a `Buffer`.
#### `fs.realpath(filepath[, opts], callback)`
Callback version of `fs.realpath()`.
#### `const resolved = fs.realpathSync(filepath[, opts])`
Synchronous version of `fs.realpath()`.
#### `const target = await fs.readlink(filepath[, opts])`
Read the target of a symbolic link.
Options include:
```js
options = {
encoding: 'utf8'
}
```
#### `fs.readlink(filepath[, opts], callback)`
Callback version of `fs.readlink()`.
#### `const target = fs.readlinkSync(filepath[, opts])`
Synchronous version of `fs.readlink()`.
#### `await fs.truncate(filename[, len])`
Truncate the file at `filename` to `len` bytes. `len` defaults to `0`.
#### `fs.truncate(filename[, len], callback)`
Callback version of `fs.truncate()`.
#### `fs.truncateSync(filename[, len])`
Synchronous version of `fs.truncate()`.
#### `await fs.symlink(target, filepath[, type])`
Create a symbolic link at `filepath` pointing to `target`. `type` may be `'file'`, `'dir'`, or `'junction'` (Windows only) or a numeric flag. On Windows, if `type` is not provided, it is inferred from the target.
#### `fs.symlink(target, filepath[, type], callback)`
Callback version of `fs.symlink()`.
#### `fs.symlinkSync(target, filepath[, type])`
Synchronous version of `fs.symlink()`.
#### `await fs.fsync(fd)`
Flush all modified in-core data of the file referred by its file descriptor to the disk device.
#### `fs.fsync(fs, callback)`
Callback version of `fs.fsync()`.
#### `fs.fsyncSync(fd)`
Synchronous version of `fs.fsync()`.
#### `await fs.fdatasync(fd)`
Similar to `fsync`, but does not flush modified metadata unless necessary.
#### `fs.fdatasync(fs, callback)`
Callback version of `fs.fdatasync()`.
#### `fs.fdatasyncSync(fd)`
Synchronous version of `fs.fdatasync()`.
#### `const dir = await fs.opendir(filepath[, opts])`
Open a directory for iteration. Returns a `Dir` object.
Options include:
```js
options = {
encoding: 'utf8',
bufferSize: 32
}
```
#### `fs.opendir(filepath[, opts], callback)`
Callback version of `fs.opendir()`.
#### `const dir = fs.opendirSync(filepath[, opts])`
Synchronous version of `fs.opendir()`.
#### `const entries = await fs.readdir(filepath[, opts])`
Read the contents of a directory. Returns an array of filenames or, if `withFileTypes` is `true`, an array of `Dirent` objects.
Options include:
```js
options = {
encoding: 'utf8',
withFileTypes: false
}
```
#### `fs.readdir(filepath[, opts], callback)`
Callback version of `fs.readdir()`.
#### `const entries = fs.readdirSync(filepath[, opts])`
Synchronous version of `fs.readdir()`.
#### `const data = await fs.readFile(filepath[, opts])`
Read the entire contents of a file. Returns a `Buffer` by default, or a string if an `encoding` is specified.
Options include:
```js
options = {
encoding: 'buffer',
flag: 'r'
}
```
#### `fs.readFile(filepath[, opts], callback)`
Callback version of `fs.readFile()`.
#### `const data = fs.readFileSync(filepath[, opts])`
Synchronous version of `fs.readFile()`.
#### `await fs.writeFile(filepath, data[, opts])`
Write `data` to a file, replacing it if it already exists.
Options include:
```js
options = {
encoding: 'utf8',
flag: 'w',
mode: 0o666
}
```
#### `fs.writeFile(filepath, data[, opts], callback)`
Callback version of `fs.writeFile()`.
#### `fs.writeFileSync(filepath, data[, opts])`
Synchronous version of `fs.writeFile()`.
#### `await fs.appendFile(filepath, data[, opts])`
Append `data` to a file, creating it if it does not exist. Accepts the same options as `fs.writeFile()` but defaults to the `'a'` flag.
#### `fs.appendFile(filepath, data[, opts], callback)`
Callback version of `fs.appendFile()`.
#### `fs.appendFileSync(filepath, data[, opts])`
Synchronous version of `fs.appendFile()`.
#### `const watcher = fs.watch(filepath[, opts], callback)`
Watch a file or directory for changes. Returns a `Watcher` object. The `callback`, if provided, is called with `(eventType, filename)` on each change.
Options include:
```js
options = {
persistent: true,
recursive: false,
encoding: 'utf8'
}
```
#### `const stream = fs.createReadStream(path[, opts])`
Create a readable stream for a file. Returns a `ReadStream`.
Options include:
```js
options = {
fd: -1,
flags: 'r',
mode: 0o666,
start: 0,
end: Infinity
}
```
If `fd` is provided, `path` may be `null` and the stream reads from the given file descriptor.
#### `const stream = fs.createWriteStream(path[, opts])`
Create a writable stream for a file. Returns a `WriteStream`.
Options include:
```js
options = {
fd: -1,
flags: 'w',
mode: 0o666
}
```
If `fd` is provided, `path` may be `null` and the stream writes to the given file descriptor.
#### `fs.constants`
An object containing file system constants. See `fs/constants` for the full list. Commonly used constants include:
- `fs.constants.O_RDONLY`, `fs.constants.O_WRONLY`, `fs.constants.O_RDWR` — file access flags
- `fs.constants.O_CREAT`, `fs.constants.O_TRUNC`, `fs.constants.O_APPEND` — file creation flags
- `fs.constants.F_OK`, `fs.constants.R_OK`, `fs.constants.W_OK`, `fs.constants.X_OK` — file accessibility flags
- `fs.constants.S_IFMT`, `fs.constants.S_IFREG`, `fs.constants.S_IFDIR`, `fs.constants.S_IFLNK` — file type flags
- `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, `fs.constants.COPYFILE_FICLONE_FORCE` — copy flags
### `Stats`
Returned by `fs.stat()`, `fs.lstat()`, and `fs.fstat()`.
#### `stats.dev`
The device identifier.
#### `stats.mode`
The file mode (type and permissions).
#### `stats.nlink`
The number of hard links.
#### `stats.uid`
The user identifier of the file owner.
#### `stats.gid`
The group identifier of the file owner.
#### `stats.rdev`
The device identifier for special files.
#### `stats.blksize`
The file system block size for I/O operations.
#### `stats.ino`
The inode number.
#### `stats.size`
The size of the file in bytes.
#### `stats.blocks`
The number of 512-byte blocks allocated.
#### `stats.atimeMs`
The access time in milliseconds since the epoch.
#### `stats.mtimeMs`
The modification time in milliseconds since the epoch.
#### `stats.ctimeMs`
The change time in milliseconds since the epoch.
#### `stats.birthtimeMs`
The creation time in milliseconds since the epoch.
#### `stats.atime`
The access time as a `Date` object.
#### `stats.mtime`
The modification time as a `Date` object.
#### `stats.ctime`
The change time as a `Date` object.
#### `stats.birthtime`
The creation time as a `Date` object.
#### `stats.isDirectory()`
Returns `true` if the file is a directory.
#### `stats.isFile()`
Returns `true` if the file is a regular file.
#### `stats.isBlockDevice()`
Returns `true` if the file is a block device.
#### `stats.isCharacterDevice()`
Returns `true` if the file is a character device.
#### `stats.isFIFO()`
Returns `true` if the file is a FIFO (named pipe).
#### `stats.isSymbolicLink()`
Returns `true` if the file is a symbolic link. Only meaningful when using `fs.lstat()`.
#### `stats.isSocket()`
Returns `true` if the file is a socket.
### `Dir`
Returned by `fs.opendir()`. Supports both synchronous and asynchronous iteration.
#### `dir.path`
The path of the directory.
#### `const dirent = await dir.read()`
Read the next directory entry. Returns a `Dirent` or `null` when all entries have been read.
#### `dir.read(callback)`
Callback version of `dir.read()`.
#### `const dirent = dir.readSync()`
Synchronous version of `dir.read()`.
#### `await dir.close()`
Close the directory handle.
#### `dir.close(callback)`
Callback version of `dir.close()`.
#### `dir.closeSync()`
Synchronous version of `dir.close()`.
### `Dirent`
Represents a directory entry, returned when iterating a `Dir` or using `fs.readdir()` with `withFileTypes: true`.
#### `dirent.parentPath`
The path of the parent directory.
#### `dirent.name`
The name of the directory entry, as a string or `Buffer` depending on the encoding.
#### `dirent.type`
The numeric type of the directory entry.
#### `dirent.isFile()`
Returns `true` if the entry is a regular file.
#### `dirent.isDirectory()`
Returns `true` if the entry is a directory.
#### `dirent.isSymbolicLink()`
Returns `true` if the entry is a symbolic link.
#### `dirent.isFIFO()`
Returns `true` if the entry is a FIFO.
#### `dirent.isSocket()`
Returns `true` if the entry is a socket.
#### `dirent.isCharacterDevice()`
Returns `true` if the entry is a character device.
#### `dirent.isBlockDevice()`
Returns `true` if the entry is a block device.
### `ReadStream`
A readable stream for file data, created by `fs.createReadStream()`. Extends `Readable` from <https://github.com/holepunchto/bare-stream>.
#### `stream.path`
The file path, or `null` if opened by file descriptor.
#### `stream.fd`
The underlying file descriptor.
#### `stream.flags`
The flags the file was opened with.
#### `stream.mode`
The mode the file was opened with.
### `WriteStream`
A writable stream for file data, created by `fs.createWriteStream()`. Extends `Writable` from <https://github.com/holepunchto/bare-stream>.
#### `stream.path`
The file path, or `null` if opened by file descriptor.
#### `stream.fd`
The underlying file descriptor.
#### `stream.flags`
The flags the file was opened with.
#### `stream.mode`
The mode the file was opened with.
### `Watcher`
Watches for file system changes, created by `fs.watch()`. Extends `EventEmitter` from <https://github.com/holepunchto/bare-events>.
#### `watcher.close()`
Stop watching for changes.
#### `watcher.ref()`
Prevent the event loop from exiting while the watcher is active.
#### `watcher.unref()`
Allow the event loop to exit even if the watcher is still active.
#### `event: 'change'`
Emitted with `(eventType, filename)` when a change is detected. `eventType` is either `'rename'` or `'change'`.
#### `event: 'error'`
Emitted with `(err)` when an error occurs.
#### `event: 'close'`
Emitted when the watcher is closed.
### `FileHandle`
Returned by `require('bare-fs/promises').open()`. Provides an object-oriented API for working with file descriptors.
#### `await handle.close()`
Close the file handle.
#### `const { bytesRead, buffer } = await handle.read(buffer[, offset[, len[, pos]]])`
Read from the file into `buffer`.
#### `const { bytesRead, buffers } = await handle.readv(buffers[, pos])`
Read from the file into an array of `buffers`.
#### `const { bytesWritten, buffer } = await handle.write(data[, offset[, len[, pos]]])`
Write `data` to the file.
#### `const { bytesWritten, buffers } = await handle.writev(buffers[, pos])`
Write an array of `buffers` to the file.
#### `const stats = await handle.stat()`
Get the status of the file.
#### `await handle.chmod(mode)`
Change the permissions of the file.
#### `await handle.chown(uid, gid)`
Change the owner and group of the file.
**NOTE**: This function is not implemented on Windows.
#### `await handle.datasync()`
Similar to `fsync`, but does not flush modified metadata unless necessary.
#### `await handle.sync()`
Flush all modified in-core data of the file.
#### `await handle.truncate(len)`
Truncate the file.
#### `await handle.utimes(mode)`
Change the access and modification times of the file.
#### `const stream = handle.createReadStream([opts])`
Create a readable stream for the file.
#### `const stream = handle.createWriteStream([opts])`
Create a writable stream for the file.
#### `handle.fd`
The file descriptor number.
#### `event: 'close'`
Emitted when the file handle is closed.
## License
Apache-2.0

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet