合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
从1078版本开始,接口前缀由hbs调整为qg,原hbs仍支持。
| 接口 | 描述 |
|---|---|
| 获取全局唯一的文件管理器,返回FileSystemManager对象。 | |
| 判断文件/目录是否存在。 | |
| 判断文件/目录是否存在(同步方法)。 | |
| 复制文件。 | |
| FileSystemManager.copyFileSync(string srcPath, string destPath) | 复制文件(同步方法)。 |
| 创建目录。 | |
| FileSystemManager.mkdirSync(string dirPath, boolean recursive) | 创建目录(同步方法)。 |
| 删除目录。 | |
| 删除目录(同步方法)。 | |
| 读取目录内文件列表。 | |
| 读取目录内文件列表(同步方法)。 | |
| 读取本地文件内容。 | |
| string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding) | 读取本地文件内容(同步方法)。 |
| 重命名文件,可以把文件从oldPath移动到newPath。 | |
| FileSystemManager.renameSync(string oldPath, string newPath) | 重命名文件,可以把文件从oldPath移动到newPath(同步方法)。 |
| 获取文件stats对象。 | |
| Stats|Array FileSystemManager.statSync(string path, boolean recursive) | 获取文件stats对象(同步方法)。 |
| 删除文件。 | |
| 删除文件(同步方法)。 | |
| 解压缩文件。 | |
| 写文件,写入内容将覆盖原有内容。 | |
| FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding) | 写文件(同步方法)。 |
| 保存临时文件到本地。 | |
| FileSystemManager.saveFileSync(string tempFilePath, string filePath) | 保存临时文件到本地(同步方法)。 |
| 在文件结尾追加内容。 | |
| FileSystemManager.appendFile的同步版本。 | |
| 获取本地临时文件或本地用户文件的文件信息。 | |
| 删除该快游戏下已保存的本地缓存文件。 | |
| 读取指定压缩类型的本地文件内容。 | |
| 同步读取指定压缩类型的本地文件内容。 | |
| 描述文件状态的对象。 | |
| 每个FileStats对象包含path和Stats。 |
获取全局唯一的文件管理器,返回FileSystemManager对象。
判断文件/目录是否存在。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| path | string | M | 要判断是否存在的文件/目录路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.access({
path : "file path",
success : function() {
console.log("access success" );
},
fail : function(data) {
console.log("access fail " + JSON.stringify(data));
},
complete : function() {
console.log("access complete" );
}
})判断文件/目录是否存在(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| path | string | 要判断是否存在的文件/目录路径。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 文件/目录不存在。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.accessSync('file path');
} catch (error) {
console.log('error = ' + error);
}复制文件。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| srcPath | string | M | 源文件路径,只可以是本地文件,如果非本地文件,需调用FileSystemManager.saveFile接口将文件保存到本地。 |
| destPath | string | M | 目标文件路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.copyFile({
srcPath : 'source file', //源文件路径,只可以是普通文件
destPath : 'target path',
success : function() {
console.log("copy success" );
},
fail : function(data) {
console.log("copy fail " + JSON.stringify(data));
},
complete : function() {
console.log("copy complete" );
}
})复制文件(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| srcPath | string | 源文件路径,只可以是本地文件,如果非本地文件,需调用FileSystemManager.saveFile接口将文件保存到本地。 |
| destPath | string | 目标文件路径。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 源文件不存在,或目标文件路径的上层目录不存在。 |
| 2 | permission denied | 指定目标文件路径没有写权限。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.copyFileSync('file path', 'dest path');
} catch (error) {
console.log('error = ' + error);
}创建目录。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| dirPath | string | M | 创建的目录路径。 |
| recursive | boolean | O | 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。默认值为false。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.mkdir({
dirPath: 'file path',
success : function() {
console.log("mkdir success" );
},
fail : function(data) {
console.log("mkdir fail " + JSON.stringify(data));
},
complete : function() {
console.log("mkdir complete" );
}
})创建目录(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| dirPath | string | 创建的目录路径。 |
| recursive | boolean | 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。默认值为false。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 上级目录不存在。 |
| 2 | permission denied | 指定目标文件路径没有写权限。 |
| 3 | file already exists | 有同名文件或目录。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.mkdirSync('dir path', false);
} catch (error) {
console.log('error = ' + error);
}删除目录。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| dirPath | string | M | 要删除的目录路径。 |
| recursive | boolean | O | 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。默认值为false。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.rmdir({
dirPath : 'file path',
success : function() {
console.log("rmdir success");
},
fail : function(data) {
console.log("rmdir fail " + JSON.stringify(data));
},
complete : function() {
console.log("rmdir complete" );
}
})删除目录(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| dirPath | string | 要删除的目录路径。 |
| recursive | boolean | 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。默认值为false。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 目录不存在。 |
| 7 | directory not empty | 目录不为空。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.rmdirSync('dir path', false);
} catch (error) {
console.log('error = ' + error);
}读取目录内文件列表。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| dirPath | string | M | 要读取的目录路径。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数 | 类型 | 说明 |
|---|---|---|
| files | arraystring | 指定目录下的文件名数组。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.readdir({
dirPath : 'file path',
success : function(res) {
console.log("readdir success res = " + JSON.stringify(res));
},
fail : function(data) {
console.log("readdir fail " + JSON.stringify(data));
},
complete : function() {
console.log("readdir complete" );
}
})读取目录内文件列表(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| dirPath | string | 要读取的目录路径。 |
Array files。
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 目录不存在。 |
var fileSystemManager = qg.getFileSystemManager();
try {
var result = fileSystemManager.readdirSync('dir path');
console.log('result = ' + JSON.stringify(result));
} catch (error) {
console.log('error = ' + error);
}读取本地文件内容。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要读取的文件的路径。 说明 路径中请勿包含@, #, %等特殊字符。 |
| encoding | string | O | 指定读取文件的字符编码,合法值为binary和utf8,默认为 binary。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数 | 类型 | 说明 |
|---|---|---|
| data | string/arraybuffer | 文件内容。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.readFile({
filePath : 'file path',
success : function(res) {
console.log("readFile success res = " + JSON.stringify(res));
},
fail : function(data) {
console.log("readFile fail " + JSON.stringify(data));
},
complete : function() {
console.log("readFile complete" );
}
})读取本地文件内容(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| filePath | string | 要读取的文件的路径。 说明 路径中请勿包含@, #, %等特殊字符。 |
| encoding | string | 指定读取文件的字符编码,合法值为binary和utf8。 |
string|ArrayBuffer data
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 目录不存在。 |
var fileSystemManager = qg.getFileSystemManager();
try {
var result = fileSystemManager.readFileSync('file path', 'binary');
console.log('result = ' + JSON.stringify(result));
} catch (error) {
console.log('error = ' + error);
}重命名文件,可以把文件从oldPath移动到newPath。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| oldPath | string | M | 源文件路径,可以是普通文件或目录。 |
| newPath | string | M | 新文件路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.rename({
oldPath : 'file path',
newPath : 'target path',
success : function() {
console.log("rename success" );
},
fail : function(data) {
console.log("rename fail " + JSON.stringify(data));
},
complete : function() {
console.log("rename complete" );
}
})重命名文件,可以把文件从oldPath移动到newPath(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| oldPath | string | 源文件路径,可以是普通文件或目录。 |
| newPath | string | 新文件路径。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 源文件不存在,或目标文件路径的上层目录不存在。 |
| 2 | permission denied | 没有写权限。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.renameSync('old path', 'new path');
} catch (error) {
console.log('error = ' + error);
}获取文件stats对象。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| path | string | M | 文件/目录路径。 |
| recursive | boolean | O | 是否递归获取目录下的每个文件的stats信息。默认值为false。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.stat({
path: 'file path',
success : function(res) {
//当 recursive 为 false 时,res.stats 是一个 Stats 对象
var st = res.stats;
},
fail : function(data) {
console.log("rename fail " + JSON.stringify(data));
},
complete : function() {
console.log("stat complete" );
}
})获取文件stats对象(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| path | string | 文件/目录路径。 |
| recursive | boolean | 是否递归获取目录下的每个文件的stats信息。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 文件不存在。 |
var fileSystemManager = qg.getFileSystemManager();
try {
var result = fileSystemManager.statSync('path', false);
console.log('result = ' + JSON.stringify(result));
} catch (error) {
console.log('error = ' + error);
}删除文件。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要删除的文件路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.unlink({
filePath : 'file path',
success : function() {
console.log("unlink success" );
},
fail : function(data) {
console.log("unlink fail " + JSON.stringify(data));
},
complete : function() {
console.log("unlink complete" );
}
})删除文件(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| filePath | string | 要删除的文件路径。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 文件不存在。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.unlinkSync('path');
} catch (error) {
console.log('error = ' + error);
}解压缩文件。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| zipFilePath | string | M | 源文件路径,只可以是 zip 压缩文件。 |
| targetPath | string | M | 目标目录路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.unzip({
zipFilePath: 'file path',
targetPath: 'target_path',
success : function() {console.log("unzip success" );},
fail : function(data) {console.log("unzip fail " + JSON.stringify(data));},
complete : function() {console.log("unzip complete" );}
})写文件,写入内容将覆盖原有内容。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要写入的文件路径。 |
| data | string/arraybuffer | M | 要写入的文本或二进制数据。 |
| encoding | string | O | 指定写入文件的字符编码。合法值为utf8和binary,默认值为utf8。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名称 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.writeFile({
filePath : 'file path',
data: 'data string or arraybuffer',
success : function() {
console.log("writeFile success" );
},
fail : function(data) {
console.log("writeFile fail " + JSON.stringify(data));
},
complete : function() {
console.log("writeFile complete" );
}
})写文件(同步方法)。
| 参数 | 类型 | 说明 |
|---|---|---|
| filePath | string | 要写入的文件路径。 |
| data | string/arraybuffer | 要写入的文本或二进制数据。 |
| encoding | string | 指定写入文件的字符编码。合法值为utf8和binary。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 指定的文件不存在, 或是一个目录。 |
| 2 | permission denied | 指定目标文件路径没有写权限。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.writeFileSync('file path', 'data', 'binary');
} catch (error) {
console.log('error = ' + error);
}保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath将不可用。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| tempFilePath | string | M | 临时存储文件路径。 |
| filePath | string | M | 要存储的文件路径。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function | O | 接口调用失败的回调函数,fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数 | 类型 | 说明 |
|---|---|---|
| savedFilePath | string | 存储后的文件路径。 |
| 参数名 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.saveFile({
tempFilePath: 'temp file path',
filePath: 'target file path',
success : function(res) {
console.log("saveFile success res = " + JSON.stringify(res));
},
fail : function(data) {
console.log("saveFile fail " + JSON.stringify(data));
},
complete : function() {
console.log("saveFile complete" );
}
})保存临时文件到本地(同步方法)。此接口会移动临时文件,因此调用成功后,tempFilePath将不可用。
| 参数 | 类型 | 说明 |
|---|---|---|
| tempFilePath | string | 临时存储文件路径。 |
| filePath | string | 要存储的文件路径。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 指定的文件不存在, 或是一个目录。 |
| 2 | permission denied | 指定目标文件路径没有写权限。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.saveFileSync('temp file path', 'file path');
} catch (error) {
console.log('error = ' + error);
}在文件结尾追加内容。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要写入的文件路径。 |
| data | string/arraybuffer | M | 要写入的文本或二进制数据。 |
| encoding | string | O | 指定写入文件的字符编码,合法值为binary和utf8,默认为 utf8。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.appendFile({
filePath: 'file path',
data: 'data',
encoding: 'binary',
success : function() {
console.log("appendFile success ");
},
fail : function(data) {
console.log("appendFile fail " + JSON.stringify(data));
},
complete : function() {
console.log("appendFile complete" );
}
})FileSystemManager.appendFile的同步版本。
| 参数 | 类型 | 说明 |
|---|---|---|
| filePath | string | 要写入的文件路径。 |
| data | string/arraybuffer | 要写入的文本或二进制数据。 |
| encoding | string | 指定写入文件的字符编码,合法值为binary和utf8。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 1 | no such file or directory | 指定的文件不存在,或是一个目录。 |
| 2 | permission denied | 指定目标文件路径没有写权限。 |
var fileSystemManager = qg.getFileSystemManager();
try {
fileSystemManager.appendFileSync('file path', 'data', 'binary');
} catch (error) {
console.log('error = ' + error);
}获取本地临时文件或本地用户文件的文件信息。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要读取的文件路径。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function(object res) | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数 | 类型 | 说明 |
|---|---|---|
| size | number | 文件大小,以字节为单位。 |
| 参数名 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
删除该快游戏下已保存的本地缓存文件。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要删除的文件路径。 |
| success | function | O | 接口调用成功的回调函数。 |
| fail | function(Object res) | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 若有函数传入,将在成功、失败后调用该函数。 |
| 参数名 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
读取指定压缩类型的本地文件内容。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要写入的文件路径。 |
| compressionAlgorithm | string | M | 文件的压缩类型。目前仅支持填写“br”,即brotli压缩文件。 |
| success | function | O | 接口调用成功的回调函数,请参见success回调函数参数。 |
| fail | function | O | 接口调用失败的回调函数,请参见fail回调函数参数。 |
| complete | function | O | 接口调用完成的回调函数。当有函数传入时,将在调用成功和调用失败后调用该函数。 |
| 参数名 | 类型 | 说明 |
|---|---|---|
| data | arraybuffer | 文件内容。 |
| 参数名 | 说明 |
|---|---|
| errCode | 错误码。 |
| errMsg | 错误信息。 |
var fileSystemManager = qg.getFileSystemManager();
fileSystemManager.readCompressedFile({
filePath :`${rt.env.USER_DATA_PATH}/test.br`,
compressionAlgorithm: 'br',
success : function(res) {
console.log("readCompressedFile success data: " + JSON.stringify(res?.data));
},
fail : function(data) {
console.log("readCompressedFile fail: " + JSON.stringify(data));
},
complete : function() {
console.log("readCompressedFile complete");
}
})同步读取指定压缩类型的本地文件内容。
| 参数 | 类型 | 必填(M)/选填(O) | 说明 |
|---|---|---|---|
| filePath | string | M | 要写入的文件路径。 |
| compressionAlgorithm | string | M | 文件的压缩类型。目前仅支持填写“br”,即brotli压缩文件。 |
| 参数名 | 类型 | 说明 |
|---|---|---|
| data | arraybuffer | 文件内容。 |
var fileSystemManager = qg.getFileSystemManager();
try {
var result = fileSystemManager.readCompressedFileSync({
filePath :`${rt.env.USER_DATA_PATH}/test.br`,
compressionAlgorithm: 'br',
});
console.log("readCompressedFileSync success data: " + JSON.stringify(result));
} catch (error) {
console.log('readCompressedFileSync error: ' + JSON.stringify(error));
}描述文件状态的对象。
| 属性 | 类型 | 说明 |
|---|---|---|
| mode | string | 文件的类型和存取的权限,对应POSIX stat.st_mode。 |
| size | number | 文件大小,单位:B,对应POSIX stat.st_size。 说明 如果您在manifest.json中指定的minPlatformVersion大于或等于1126,该字段会返回准确的文件字节数。如果您指定的minPlatformVersion小于1126,则该字段返回的值会比实际值多一个字节。 |
| lastAccessedTime | number | 文件最近一次被存取或被执行的时间,UNIX时间戳,对应POSIX stat.st_atime。 |
| lastModifiedTime | number | 文件最后一次被修改的时间,UNIX时间戳,对应POSIX stat.st_mtime。 |
| 方法名称 | 说明 |
|---|---|
| boolean Stats.isDirectory() | 判断当前文件是否是一个目录。 |
| boolean Stats.isFile() | 判断当前文件是否是一个普通文件。 |
每个FileStats对象包含path和Stats。
| 属性 | 类型 | 说明 |
|---|---|---|
| path | string | 文件/目录路径。 |
| stats | Stats 对象,即描述文件状态的对象。 |
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| -1 | unknown error occurred | 未知错误。 |
| 0 | file operate success | 成功。 |
| 1 | no such file or directory | 找不到文件或目录。 |
| 2 | permission denied | 权限错误。 |
| 3 | file already exists | 文件已存在。 |
| 4 | not a directory | 非文件路径。 |
| 5 | not a file | 非文件。 |
| 6 | the maximum size of the file storage limit is exceeded | 超过了文件存储空间限制。 |
| 7 | directory not empty | 目录非空。 |
| 8 | create directory fail | 创建文件路径失败。 |
| 9 | unsupported compression algorithm | 不支持的文件压缩类型。 |
| 10 | decompress fail | 解压失败。例如,压缩文件已损坏,或者压缩文件实际使用的压缩算法与传入的compressionAlgorithm不一致。 |