使用zlib.decompressFile api进行解压操作,一直报错900002 传入的目标文件错误
读取服务端加密数据进行本地解密并进行解压缩操作,一直在解压环节报错文件路径问题
代码:
let filePath = MMKVUtil.filePath+'/dataCache';
fs.mkdir(filePath).then(() => {
console.info("mkdir succeed");
let inputFilePath = filePath+'/data.zip';
let file = fs.openSync(inputFilePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.writeSync(file.fd,outPutData.buffer);
fs.closeSync(file);
let res = fs.accessSync(inputFilePath);
if (res) {
console.info("file exists");
} else {
console.info("file not exists");
}
let outFilePath = filePath+'/data.json';
let file2 = fs.openSync(outFilePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.closeSync(file2);
let res2 = fs.accessSync(outFilePath);
if (res2) {
console.info("file exists");
} else {
console.info("file not exists");
}
try {
zlib.decompressFile(inputFilePath, outFilePath, (errData: BusinessError) => {
if (errData !== null) {
console.error(`decompressFile failed. code is ${errData.code}, message is ${errData.message}`);
}
})
} catch(errData) {
console.error(`decompressFile failed. code is ${errData.code}, message is ${errData.message}`);
}
}).catch((err: BusinessError) => {
console.error("mkdir failed with error message: " + err.message + ", error code: " + err.code);
});
zlib.decompressFile的第二个参数指定的解压后的文件夹路径,提供的代码片段let outFilePath = filePath+’/data.json’;
outFile为一个文件路径,可以尝试将其修改为文件夹路径可解决900002的报错