trufs
v1.2.38
Published
Trusty file methods.
Downloads
92
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?)
trufs/types
│
├── 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 | read_options | 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 | read_options | Read options. |returns String | Buffer
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 | write_options | Write options. |returns Promise
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 | write_options | Write options. |returns Void
Example:
fs.writeFileSync('./config.json', JSON.stringify({}));
Types
| Type | | -------------- | | Fs | | ReadOptions | | WriteOptions |
