Initial commit
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
|
||||
|
||||
project(bare_fs C)
|
||||
|
||||
add_bare_module(bare_fs)
|
||||
|
||||
target_sources(
|
||||
${bare_fs}
|
||||
PRIVATE
|
||||
binding.c
|
||||
)
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+989
@@ -0,0 +1,989 @@
|
||||
# bare-fs
|
||||
|
||||
Native file system operations for Bare. The API closely follows that of the Node.js `fs` module.
|
||||
|
||||
```
|
||||
npm i bare-fs
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('bare-fs')
|
||||
|
||||
const fd = await fs.open('hello.txt')
|
||||
|
||||
const buffer = Buffer.alloc(1024)
|
||||
|
||||
try {
|
||||
const length = await fs.read(fd, buffer)
|
||||
|
||||
console.log('Read', length, 'bytes')
|
||||
} finally {
|
||||
await fs.close(fd)
|
||||
}
|
||||
```
|
||||
|
||||
## 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,
|
||||
recursive: 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
|
||||
+2889
File diff suppressed because it is too large
Load Diff
+1
@@ -0,0 +1 @@
|
||||
module.exports = require.addon()
|
||||
+1232
File diff suppressed because it is too large
Load Diff
+2842
File diff suppressed because it is too large
Load Diff
+49
@@ -0,0 +1,49 @@
|
||||
declare const constants: {
|
||||
O_RDWR: number
|
||||
O_RDONLY: number
|
||||
O_WRONLY: number
|
||||
O_CREAT: number
|
||||
O_TRUNC: number
|
||||
O_APPEND: number
|
||||
|
||||
F_OK: number
|
||||
R_OK: number
|
||||
W_OK: number
|
||||
X_OK: number
|
||||
|
||||
S_IFMT: number
|
||||
S_IFREG: number
|
||||
S_IFDIR: number
|
||||
S_IFCHR: number
|
||||
S_IFLNK: number
|
||||
S_IFBLK: number
|
||||
S_IFIFO: number
|
||||
S_IFSOCK: number
|
||||
|
||||
S_IRUSR: number
|
||||
S_IWUSR: number
|
||||
S_IXUSR: number
|
||||
S_IRGRP: number
|
||||
S_IWGRP: number
|
||||
S_IXGRP: number
|
||||
S_IROTH: number
|
||||
S_IWOTH: number
|
||||
S_IXOTH: number
|
||||
|
||||
UV_DIRENT_UNKNOWN: number
|
||||
UV_DIRENT_FILE: number
|
||||
UV_DIRENT_DIR: number
|
||||
UV_DIRENT_LINK: number
|
||||
UV_DIRENT_FIFO: number
|
||||
UV_DIRENT_SOCKET: number
|
||||
UV_DIRENT_CHAR: number
|
||||
UV_DIRENT_BLOCK: number
|
||||
|
||||
COPYFILE_EXCL: number
|
||||
COPYFILE_FICLONE: number
|
||||
COPYFILE_FICLONE_FORCE: number
|
||||
UV_FS_SYMLINK_DIR: number
|
||||
UV_FS_SYMLINK_JUNCTION: number
|
||||
}
|
||||
|
||||
export = constants
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
const binding = require('../binding')
|
||||
|
||||
module.exports = {
|
||||
O_RDWR: binding.O_RDWR,
|
||||
O_RDONLY: binding.O_RDONLY,
|
||||
O_WRONLY: binding.O_WRONLY,
|
||||
O_CREAT: binding.O_CREAT,
|
||||
O_TRUNC: binding.O_TRUNC,
|
||||
O_APPEND: binding.O_APPEND,
|
||||
|
||||
F_OK: binding.F_OK || 0,
|
||||
R_OK: binding.R_OK || 0,
|
||||
W_OK: binding.W_OK || 0,
|
||||
X_OK: binding.X_OK || 0,
|
||||
|
||||
S_IFMT: binding.S_IFMT,
|
||||
S_IFREG: binding.S_IFREG,
|
||||
S_IFDIR: binding.S_IFDIR,
|
||||
S_IFCHR: binding.S_IFCHR,
|
||||
S_IFLNK: binding.S_IFLNK,
|
||||
S_IFBLK: binding.S_IFBLK || 0,
|
||||
S_IFIFO: binding.S_IFIFO || 0,
|
||||
S_IFSOCK: binding.S_IFSOCK || 0,
|
||||
|
||||
S_IRUSR: binding.S_IRUSR || 0,
|
||||
S_IWUSR: binding.S_IWUSR || 0,
|
||||
S_IXUSR: binding.S_IXUSR || 0,
|
||||
S_IRGRP: binding.S_IRGRP || 0,
|
||||
S_IWGRP: binding.S_IWGRP || 0,
|
||||
S_IXGRP: binding.S_IXGRP || 0,
|
||||
S_IROTH: binding.S_IROTH || 0,
|
||||
S_IWOTH: binding.S_IWOTH || 0,
|
||||
S_IXOTH: binding.S_IXOTH || 0,
|
||||
|
||||
UV_DIRENT_UNKNOWN: binding.UV_DIRENT_UNKNOWN,
|
||||
UV_DIRENT_FILE: binding.UV_DIRENT_FILE,
|
||||
UV_DIRENT_DIR: binding.UV_DIRENT_DIR,
|
||||
UV_DIRENT_LINK: binding.UV_DIRENT_LINK,
|
||||
UV_DIRENT_FIFO: binding.UV_DIRENT_FIFO,
|
||||
UV_DIRENT_SOCKET: binding.UV_DIRENT_SOCKET,
|
||||
UV_DIRENT_CHAR: binding.UV_DIRENT_CHAR,
|
||||
UV_DIRENT_BLOCK: binding.UV_DIRENT_BLOCK,
|
||||
|
||||
COPYFILE_EXCL: binding.UV_FS_COPYFILE_EXCL,
|
||||
COPYFILE_FICLONE: binding.UV_FS_COPYFILE_FICLONE,
|
||||
COPYFILE_FICLONE_FORCE: binding.UV_FS_COPYFILE_FICLONE_FORCE,
|
||||
UV_FS_SYMLINK_DIR: binding.UV_FS_SYMLINK_DIR,
|
||||
UV_FS_SYMLINK_JUNCTION: binding.UV_FS_SYMLINK_JUNCTION
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
declare class FileError extends Error {
|
||||
private constructor(msg: string)
|
||||
|
||||
readonly code: string
|
||||
readonly operation?: string
|
||||
readonly path?: string
|
||||
readonly destination?: string
|
||||
readonly fd?: number
|
||||
}
|
||||
|
||||
export = FileError
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
const os = require('bare-os')
|
||||
|
||||
module.exports = class FileError extends Error {
|
||||
constructor(msg, opts = {}) {
|
||||
const { code, operation = null, path = null, destination = null, fd = -1 } = opts
|
||||
|
||||
if (operation !== null) msg += describe(operation, opts)
|
||||
|
||||
super(`${code}: ${msg}`)
|
||||
|
||||
this.code = code
|
||||
|
||||
if (operation !== null) this.operation = operation
|
||||
if (path !== null) this.path = path
|
||||
if (destination !== null) this.destination = destination
|
||||
if (fd !== -1) this.fd = fd
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'FileError'
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get errno() {
|
||||
return os.constants.errnos[this.code]
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get syscall() {
|
||||
return this.operation
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get dest() {
|
||||
return this.destination
|
||||
}
|
||||
}
|
||||
|
||||
function describe(operation, opts) {
|
||||
const { path = null, destination = null, fd = -1 } = opts
|
||||
|
||||
let result = `, ${operation}`
|
||||
|
||||
if (path !== null) {
|
||||
result += ` ${JSON.stringify(path)}`
|
||||
|
||||
if (destination !== null) {
|
||||
result += ` -> ${JSON.stringify(destination)}`
|
||||
}
|
||||
} else if (fd !== -1) {
|
||||
result += ` ${fd}`
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "bare-fs",
|
||||
"version": "4.7.2",
|
||||
"description": "Native file system operations for Bare",
|
||||
"exports": {
|
||||
"./package": "./package.json",
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./promises": {
|
||||
"types": "./promises.d.ts",
|
||||
"default": "./promises.js"
|
||||
},
|
||||
"./constants": {
|
||||
"types": "./lib/constants.d.ts",
|
||||
"default": "./lib/constants.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"promises.js",
|
||||
"promises.d.ts",
|
||||
"binding.c",
|
||||
"binding.js",
|
||||
"CMakeLists.txt",
|
||||
"lib",
|
||||
"prebuilds"
|
||||
],
|
||||
"addon": true,
|
||||
"scripts": {
|
||||
"format": "prettier --write . && lunte --fix",
|
||||
"lint": "prettier --check . && lunte",
|
||||
"test": "brittle-bare --coverage test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/holepunchto/bare-fs.git"
|
||||
},
|
||||
"author": "Holepunch",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/holepunchto/bare-fs/issues"
|
||||
},
|
||||
"homepage": "https://github.com/holepunchto/bare-fs#readme",
|
||||
"engines": {
|
||||
"bare": ">=1.16.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bare-events": "^2.5.4",
|
||||
"bare-path": "^3.0.0",
|
||||
"bare-stream": "^2.6.4",
|
||||
"bare-url": "^2.2.2",
|
||||
"fast-fifo": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bare-buffer": "^3.0.2",
|
||||
"bare-crypto": "^1.11.2",
|
||||
"brittle": "^3.1.1",
|
||||
"cmake-bare": "^1.1.7",
|
||||
"lunte": "^1.6.0",
|
||||
"prettier": "^3.4.1",
|
||||
"prettier-config-holepunch": "^2.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bare-buffer": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bare-buffer": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+313
@@ -0,0 +1,313 @@
|
||||
import EventEmitter, { EventMap } from 'bare-events'
|
||||
import Buffer, { BufferEncoding } from 'bare-buffer'
|
||||
import {
|
||||
constants,
|
||||
AppendFileOptions,
|
||||
CpOptions,
|
||||
Dir,
|
||||
Dirent,
|
||||
Flag,
|
||||
MkdirOptions,
|
||||
OpendirOptions,
|
||||
Path,
|
||||
ReadFileOptions,
|
||||
ReadStream,
|
||||
ReadStreamOptions,
|
||||
ReaddirOptions,
|
||||
ReadlinkOptions,
|
||||
RealpathOptions,
|
||||
RmOptions,
|
||||
StatFs,
|
||||
Stats,
|
||||
Watcher,
|
||||
WatcherOptions,
|
||||
WriteFileOptions,
|
||||
WriteStream,
|
||||
WriteStreamOptions
|
||||
} from '.'
|
||||
|
||||
export { constants }
|
||||
|
||||
interface FileHandleEvents extends EventMap {
|
||||
close: []
|
||||
}
|
||||
|
||||
interface FileHandle extends EventEmitter<FileHandleEvents>, AsyncDisposable {
|
||||
readonly fd: number
|
||||
|
||||
close(): Promise<void>
|
||||
|
||||
read(
|
||||
buffer: Buffer | ArrayBufferView,
|
||||
offset?: number,
|
||||
len?: number,
|
||||
pos?: number
|
||||
): Promise<number>
|
||||
|
||||
readv(buffers: ArrayBufferView[], position?: number): Promise<number>
|
||||
|
||||
write(
|
||||
data: Buffer | ArrayBufferView,
|
||||
offset?: number,
|
||||
len?: number,
|
||||
pos?: number
|
||||
): Promise<number>
|
||||
|
||||
write(data: string, pos?: number, encoding?: BufferEncoding): Promise<number>
|
||||
|
||||
stat(): Promise<Stats>
|
||||
|
||||
chmod(mode: string | number): Promise<void>
|
||||
|
||||
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
|
||||
|
||||
createWriteStream(opts?: WriteStreamOptions): WriteStream
|
||||
}
|
||||
|
||||
declare class FileHandle {
|
||||
private constructor(fd: number)
|
||||
}
|
||||
|
||||
export function open(
|
||||
filepath: Path,
|
||||
flags?: Flag | number,
|
||||
mode?: string | number
|
||||
): Promise<FileHandle>
|
||||
|
||||
export function access(filepath: Path, mode?: number): Promise<void>
|
||||
|
||||
export function appendFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
opts?: AppendFileOptions
|
||||
): Promise<void>
|
||||
|
||||
export function appendFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
encoding: BufferEncoding
|
||||
): Promise<void>
|
||||
|
||||
export function chmod(filepath: Path, mode: string | number): Promise<void>
|
||||
|
||||
export function chown(filepath: Path, uid: number, gid: number): Promise<void>
|
||||
|
||||
export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
|
||||
|
||||
export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
|
||||
|
||||
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>
|
||||
|
||||
export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
|
||||
|
||||
export function mkdir(filepath: Path, mode: number): Promise<void>
|
||||
|
||||
export function mkdtemp(prefix: Path): Promise<string>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
opts: OpendirOptions & { encoding?: BufferEncoding }
|
||||
): Promise<Dir<string>>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
opts: OpendirOptions & { encoding: 'buffer' }
|
||||
): Promise<Dir<Buffer>>
|
||||
|
||||
export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
|
||||
|
||||
export function opendir(filepath: Path, encoding: BufferEncoding): Promise<Dir<string>>
|
||||
|
||||
export function opendir(filepath: Path, encoding: 'buffer'): Promise<Dir<Buffer>>
|
||||
|
||||
export function opendir(filepath: Path, encoding: BufferEncoding | 'buffer'): Promise<Dir>
|
||||
|
||||
export function opendir(filepath: Path): Promise<Dir<string>>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
opts: ReadFileOptions & { encoding: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
opts: ReadFileOptions & { encoding?: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function readFile(filepath: Path, opts: ReadFileOptions): Promise<string | Buffer>
|
||||
|
||||
export function readFile(filepath: Path, encoding: BufferEncoding): Promise<string>
|
||||
|
||||
export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
encoding?: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readFile(filepath: Path): Promise<Buffer>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding }
|
||||
): Promise<Dir<string>[] | string[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
|
||||
): Promise<Dir<string>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
|
||||
): Promise<string[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer' }
|
||||
): Promise<Dir<Buffer>[] | Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
|
||||
): Promise<Dir<Buffer>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
|
||||
): Promise<Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { withFileTypes: true }
|
||||
): Promise<Dir<string | Buffer>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { withFileTypes?: false }
|
||||
): Promise<string[] | Buffer[]>
|
||||
|
||||
export function readdir(filepath: Path, opts: ReaddirOptions): Promise<Dir[] | string[] | Buffer[]>
|
||||
|
||||
export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
|
||||
|
||||
export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string[] | Buffer[]>
|
||||
|
||||
export function readdir(filepath: Path): Promise<string[]>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
opts: ReadlinkOptions & { encoding?: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
opts: ReadlinkOptions & { encoding: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function readlink(filepath: Path, opts: ReadlinkOptions): Promise<string | Buffer>
|
||||
|
||||
export function readlink(filepath: Path, encoding: BufferEncoding): Promise<string>
|
||||
|
||||
export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readlink(filepath: Path): Promise<string>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
opts: RealpathOptions & { encoding?: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
opts: RealpathOptions & { encoding: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function realpath(filepath: Path, opts: RealpathOptions): Promise<string | Buffer>
|
||||
|
||||
export function realpath(filepath: Path, encoding: BufferEncoding): Promise<string>
|
||||
|
||||
export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function realpath(filepath: Path): Promise<string>
|
||||
|
||||
export function rename(src: Path, dst: Path): Promise<void>
|
||||
|
||||
export function rm(filepath: Path, opts?: RmOptions): Promise<void>
|
||||
|
||||
export function rmdir(filepath: Path): Promise<void>
|
||||
|
||||
export function stat(filepath: Path): Promise<Stats>
|
||||
|
||||
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>
|
||||
|
||||
export function unlink(filepath: Path): Promise<void>
|
||||
|
||||
export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
|
||||
|
||||
export function watch(
|
||||
filepath: Path,
|
||||
opts: WatcherOptions & { encoding?: BufferEncoding }
|
||||
): Watcher<string>
|
||||
|
||||
export function watch(
|
||||
filepath: Path,
|
||||
opts: WatcherOptions & { encoding: 'buffer' }
|
||||
): Watcher<Buffer>
|
||||
|
||||
export function watch(filepath: Path, opts: WatcherOptions): Watcher
|
||||
|
||||
export function watch(filepath: Path, encoding: BufferEncoding): Watcher<string>
|
||||
|
||||
export function watch(filepath: Path, encoding: 'buffer'): Watcher<Buffer>
|
||||
|
||||
export function watch(filepath: Path, encoding: BufferEncoding | 'buffer'): Watcher
|
||||
|
||||
export function watch(filepath: Path): Watcher<string>
|
||||
|
||||
export function writeFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
opts?: WriteFileOptions
|
||||
): Promise<void>
|
||||
|
||||
export function writeFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
encoding: BufferEncoding
|
||||
): Promise<void>
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
const EventEmitter = require('bare-events')
|
||||
const fs = require('.')
|
||||
|
||||
class FileHandle extends EventEmitter {
|
||||
constructor(fd) {
|
||||
super()
|
||||
|
||||
this.fd = fd
|
||||
}
|
||||
|
||||
async close() {
|
||||
await fs.close(this.fd)
|
||||
|
||||
this.fd = -1
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
async read(buffer, ...args) {
|
||||
return {
|
||||
bytesRead: await fs.read(this.fd, buffer, ...args),
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
async readv(buffers, ...args) {
|
||||
return {
|
||||
bytesRead: await fs.readv(this.fd, buffers, ...args),
|
||||
buffers
|
||||
}
|
||||
}
|
||||
|
||||
async write(buffer, ...args) {
|
||||
return {
|
||||
bytesWritten: await fs.write(this.fd, buffer, ...args),
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
async writev(buffers, ...args) {
|
||||
return {
|
||||
bytesWritten: await fs.writev(this.fd, buffers, ...args),
|
||||
buffers
|
||||
}
|
||||
}
|
||||
|
||||
async stat() {
|
||||
return fs.fstat(this.fd)
|
||||
}
|
||||
|
||||
async chmod(mode) {
|
||||
await fs.fchmod(this.fd, mode)
|
||||
}
|
||||
|
||||
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) {
|
||||
return fs.createReadStream(null, { ...opts, fd: this.fd })
|
||||
}
|
||||
|
||||
createWriteStream(opts) {
|
||||
return fs.createWriteStream(null, { ...opts, fd: this.fd })
|
||||
}
|
||||
|
||||
async [Symbol.asyncDispose]() {
|
||||
await this.close()
|
||||
}
|
||||
}
|
||||
|
||||
exports.open = async function open(filepath, flags, mode) {
|
||||
return new FileHandle(await fs.open(filepath, flags, mode))
|
||||
}
|
||||
|
||||
exports.access = fs.access
|
||||
exports.appendFile = fs.appendFile
|
||||
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
|
||||
exports.readFile = fs.readFile
|
||||
exports.readdir = fs.readdir
|
||||
exports.readlink = fs.readlink
|
||||
exports.realpath = fs.realpath
|
||||
exports.rename = fs.rename
|
||||
exports.rm = fs.rm
|
||||
exports.rmdir = fs.rmdir
|
||||
exports.stat = fs.stat
|
||||
exports.statfs = fs.statfs
|
||||
exports.truncate = fs.truncate
|
||||
exports.symlink = fs.symlink
|
||||
exports.unlink = fs.unlink
|
||||
exports.utimes = fs.utimes
|
||||
exports.watch = fs.watch
|
||||
exports.writeFile = fs.writeFile
|
||||
Reference in New Issue
Block a user