原子操作

飞道科技

@dfeidao/atom-wxapp > api_file文件操作

External module: api_file文件操作

Index

Functions


Functions

compressImage

compressImage(src: string, quality: number): Promise<object>

Defined in api/media/compress-image.ts:16

压缩图片接口,可选压缩质量

see: 微信官方文档

example:

import compressImage from '@dfeidao/atom-wxapp/api/file/compress-image';
const res = await compressImage('filePath');

Parameters:

Name Type Description
src string 图片路径,图片的路径,可以是相对路径、临时文件路径、存储文件路径
quality number 压缩质量,范围0~100,数值越小,质量越低,压缩率越高(仅对jpg有效)

Returns: Promise<object>


fs_access

fs_access(path: string): Promise<boolean>

Defined in api/file/fs-access.ts:15

判断文件/目录是否存在

see: 微信官方文档

example:

import fs_access from '@dfeidao/atom-wxapp/api/file/fs-access';
const res = await fs_access('path'); // true \|\| false

Parameters:

Name Type Description
path string 要判断是否存在的文件/目录路径

Returns: Promise<boolean>


fs_append_file

fs_append_file(filePath: string, data: string | ArrayBuffer, encoding?: “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1”): Promise<boolean>

Defined in api/file/fs-append-file.ts:17

在文件结尾追加内容

see: 微信官方文档

example:

import fs_append_file from '@dfeidao/atom-wxapp/api/file/fs-append-file';
const res = await fs_append_file('filePath',data); // true \|\| false

Parameters:

Name Type Description
filePath string 要追加内容的文件路径
data string | ArrayBuffer 要追加内容的文件路径
Optional encoding “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1” 可选项,指定写入文件的字符编码,默认为utf8

Returns: Promise<boolean>


fs_copy_file

fs_copy_file(srcPath: string, destPath: string): Promise<boolean>

Defined in api/file/fs-copy-file.ts:16

复制文件

see: 微信官方文档

example:

import fs_copy_file from '@dfeidao/atom-wxapp/api/file/fs-copy-file';
const res = await fs_copy_file('srcPath','destPath); // true \|\| false

Parameters:

Name Type Description
srcPath string 源文件路径,只可以是普通文件
destPath string 目标文件路径

Returns: Promise<boolean>


fs_mkdir

fs_mkdir(dirPath: string, recursive?: undefined | false | true): Promise<boolean>

Defined in api/file/fs-mkdir.ts:16

创建目录

see: 微信官方文档

example:

import fs_mkdir from '@dfeidao/atom-wxapp/api/file/fs-mkdir';
const res = await fs_mkdir('dirPath'); // true \|\| false

Parameters:

Name Type Description
dirPath string 创建的目录路径
Optional recursive undefined | false | true 可选项是否递归(默认为否)

Returns: Promise<boolean>


fs_read_file

fs_read_file(filePath: string, encoding?: “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1”): Promise<object>

Defined in api/file/fs-read-file.ts:16

读取本地文件内容

see: 微信官方文档

example:

import fs_read_file from '@dfeidao/atom-wxapp/api/file/fs-read-file';
const res = await fs_read_file('filePath'); // { msg: ArrayBuffer, success: true }

Parameters:

Name Type Description
filePath string 要读取的文件的路径
Optional encoding “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1” 可选项,制定读取文件的字符编码(默认为utf8)

Returns: Promise<object>


fs_readdir

fs_readdir(dirPath: string): Promise<object>

Defined in api/file/fs-readdir.ts:15

读取目录内文件列表

see: 微信官方文档

example:

import fs_readdir from '@dfeidao/atom-wxapp/api/file/fs-readdir';
const res = await fs_readdir('dirPath'); {    msg: ["miniprogramLog", "test.txt"], success: true }

Parameters:

Name Type Description
dirPath string 要读取的目录路径

Returns: Promise<object>


fs_rename

fs_rename(oldPath: string, newPath: string): Promise<boolean>

Defined in api/file/fs-rename.ts:16

重命名文件。可以把文件从 oldPath 移动到 newPath

see: 微信官方文档

example:

import fs_rename from '@dfeidao/atom-wxapp/api/file/fs-rename';
const res = await fs_rename('oldPath','newPath'); //  true \|\| false

Parameters:

Name Type Description
oldPath string 源文件路径,可以是普通文件或目录
newPath string 新文件路径

Returns: Promise<boolean>


fs_rmdir

fs_rmdir(dirPath: string, recursive?: undefined | false | true): Promise<boolean>

Defined in api/file/fs-rmdir.ts:16

删除目录

see: 微信官方文档

example:

import fs_rmdir from '@dfeidao/atom-wxapp/api/file/fs-rmdir';
const res = await fs_rmdir('dirPath'); //  true \|\| false

Parameters:

Name Type Description
dirPath string 要删除的目录路径
Optional recursive undefined | false | true 可选项,是否递归删除目录(默认为否)

Returns: Promise<boolean>


fs_stat

fs_stat(path: string, recursive?: undefined | false | true): Promise<object>

Defined in api/file/fs-stat.ts:18

获取文件 Stats 对象(同步)

see: 微信官方文档

example:

import fs_stat from '@dfeidao/atom-wxapp/api/file/fs-stat';
const res = await fs_stat('path');{ msg : {lastAccessedTime : 1555923236 lastModifiedTime : 1555923236 mode : 16822 size : 0 }, success: true }

Parameters:

Name Type Description
path string 文件/目录路径
Optional recursive undefined | false | true 可选项,是否递归获取目录下的每个文件的 Stats 信息

Returns: Promise<object>


fs_unlink(filePath: string): Promise<boolean>

Defined in api/file/fs-unlink.ts:15

删除文件

see: 微信官方文档

example:

import fs_unlink from '@dfeidao/atom-wxapp/api/file/fs-unlink';
const res = await fs_unlink('filePath'); // true \|\| false

Parameters:

Name Type
filePath string

Returns: Promise<boolean>


fs_unzip

fs_unzip(zipFilePath: string, targetPath: string): Promise<object>

Defined in api/file/fs-unzip.ts:16

解压文件

see: 微信官方文档

example:

import fs_unzip from '@dfeidao/atom-wxapp/api/file/fs-unzip';
const res = await fs_unzip('zipFilePath','targetPath); { msg : { errMsg : "unzip:ok" }, success : true }

Parameters:

Name Type Description
zipFilePath string 源文件路径,只可以是 zip 压缩文件
targetPath string 目标目录路径

Returns: Promise<object>


fs_write_file

fs_write_file(filePath: string, data: string | ArrayBuffer, encoding?: “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1”): Promise<boolean>

Defined in api/file/fs-write-file.ts:17

写文件

see: 微信官方文档

example:

import fs_write_file from '@dfeidao/atom-wxapp/api/file/fs-write-file';
const res = await fs_write_file('filePath',data); // true \|\| false

Parameters:

Name Type Description
filePath string 要写入的文件路径
data string | ArrayBuffer 要写入的文本或二进制数据
Optional encoding “ascii” | “base64” | “binary” | “hex” | “ucs2” | “ucs-2” | “utf16le” | “utf-16le” | “utf-8” | “utf8” | “latin1” 可选项,指定写入文件的字符编码(默认为utf8)

Returns: Promise<boolean>


get_file_info

get_file_info(filePath: string): Promise<object>

Defined in api/file/fs-get-file-info.ts:15

获取文件信息

see: 微信官方文档

example:

import get_file_info from '@dfeidao/atom-wxapp/api/file/get-file-info';
const res = await get_file_info('filePath'); // {msg : digest : "237c8063d553221b49c13ffce1572ecc" errMsg : "getFileInfo:ok" size : 4}

Parameters:

Name Type
filePath string

Returns: Promise<object>


get_file_info

get_file_info(filePath: string): Promise<object>

Defined in api/file/get-file-info.ts:15

获取文件信息

see: 微信官方文档

example:

import get_file_info from '@dfeidao/atom-wxapp/api/file/get-file-info';
const content = await get_file_info('filePath');

Parameters:

Name Type
filePath string

Returns: Promise<object>


get_saved_file_info

get_saved_file_info(filePath: string): Promise<object>

Defined in api/file/get-saved-file-info.ts:16

获取本地文件的文件信息。

description: 此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 get-file-info 原子操作。

see: 微信官方文档

example:

import get_saved_file_info from '@dfeidao/atom-wxapp/api/file/get-saved-file-info';
const content = await get_saved_file_info('filePath');

Parameters:

Name Type Description
filePath string 文件路径

Returns: Promise<object>


get_saved_file_list

get_saved_file_list(): Promise<object>

Defined in api/file/get-saved-file-list.ts:14

获取该小程序下已保存的本地缓存文件列表

see: 微信官方文档

example:

import get_saved_file_list from '@dfeidao/atom-wxapp/api/file/get-saved-file-list';
const file_list = await get_saved_file_list();

Returns: Promise<object>