writeFileSync
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Synchronously write data to a file in the /data
directory of the Mini Program, replacing the file if it already exists, or creating a new file if it doesn't.
Type
function writeFileSync(option: Option): void
Parameters
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
path | string|number | Y | - | File path or file descriptor | 2.0 |
data | ArrayBuffer|string|DataView | Y | - | Data to be written to the target file | 2.0 |
options | Options | N | - | Other Options | 2.0 |
Options
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
encoding | string | N | utf8 | If the data format is string , you need to specify the encoding method | 2.0 |
Example
import { writeFileSync } from '@zos/fs'
const buffer = new ArrayBuffer(4)
writeFileSync({
path: 'test.txt',
data: buffer,
})
writeFileSync({
path: 'content.txt',
data: 'some content...',
options: {
encoding: 'utf8',
},
})