trufs
v1.2.33
Published
Trusty file methods.
Maintainers
Readme
Contents
About
Trusty file methods.
Features
- Respects CommonJS
- Secure with Atomically
- Functional with FS Extra
- Stable with Graceful FS
Installation
You can install it as follows.
# NPM
npm add trufs
# PNPM
pnpm add trufs
# Yarn
yarn add trufs
# Bun
bun add trufs
# Deno
deno add trufsDocumentation
Tree
Briefly as follows.
trufs
│
├── fs
│ │
│ ├── readFile(filepath, options?)
│ ├── readFileSync(filepath, options?)
│ ├── writeFile(filepath, data, options?)
│ └── writeFileSync(filepath, data, options?)
│
├── type Fs
├── type ReadOptions
└── type WriteOptionsImport
It is enough to change the fs to trufs.
- import fs from 'fs';
+ import { fs } from 'trufs';Methods
fs.readFile(filepath, options?)
Read file asynchronous.
| Parameter | Type | Default | Description | | ---------- | ------------- | -------------------- | ------------------ | |
filepath| String | | File path to read. | |options?| ReadOptions | ReadOptionsDefault | Read options. |returns Promise<String | Buffer>
Example:
await fs.readFile('./config.json');
fs.readFileSync(filepath, options?)
Read file synchronous.
| Parameter | Type | Default | Description | | ---------- | ------------- | -------------------- | ------------------ | |
filepath| String | | File path to read. | |options?| ReadOptions | ReadOptionsDefault | Read options. |Example:
fs.readFileSync('./config.json');
fs.writeFile(filepath, data, options?)
Write file asynchronous.
| Parameter | Type | Default | Description | | ---------- | -------------------- | --------------------- | ------------------- | |
filepath| String | | File path to write. | |data| String | Buffer | | Data to be written. | |options?| WriteOptions | WriteOptionsDefault | Write options. |Example:
await fs.writeFile('./config.json', JSON.stringify({}));
fs.writeFileSync(filepath, data, options?)
Write file synchronous.
| Parameter | Type | Default | Description | | ---------- | -------------------- | --------------------- | ------------------- | |
filepath| String | | File path to write. | |data| String | Buffer | | Data to be written. | |options?| WriteOptions | WriteOptionsDefault | Write options. |returns Void
Example:
fs.writeFileSync('./config.json', JSON.stringify({}));
Types
| Type | | -------------- | | Fs | | ReadOptions | | WriteOptions |
Links
License
MIT License
Copyright (c) 2025 Keift
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
