feat:fielModel.ets修改
This commit is contained in:
parent
3ac39b383b
commit
c94005445d
@ -1,20 +1,26 @@
|
|||||||
import zlib from '@ohos.zlib';
|
import zlib from '@ohos.zlib';
|
||||||
import promptAction from '@ohos.promptAction';
|
import promptAction from '@ohos.promptAction';
|
||||||
import FileUtils from '../../../utils/FileUtils';
|
import FileUtils from '../../../utils/FileUtils';
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
|
||||||
|
interface Options{
|
||||||
|
level:number
|
||||||
|
memLevel:number
|
||||||
|
strategy:number
|
||||||
|
}
|
||||||
|
|
||||||
export default class FileModel {
|
export default class FileModel {
|
||||||
public folderPath: string
|
public folderPath: string
|
||||||
// 设置文件夹
|
// 设置文件夹
|
||||||
public initFolder = async () => {
|
public initFolder = async () => {
|
||||||
const { fileUtil } = this
|
await this.fileUtil.initFolder(`/models/model_enc`);
|
||||||
await fileUtil.initFolder(`/models/model_enc`);
|
const folderPath = await this.fileUtil.initFolder(`/models`);
|
||||||
const folderPath = await fileUtil.initFolder(`/models`);
|
|
||||||
this.folderPath = folderPath;
|
this.folderPath = folderPath;
|
||||||
}
|
}
|
||||||
//后续文件路径待替换
|
//后续文件路径待替换
|
||||||
private fileUtil: FileUtils
|
private fileUtil: FileUtils
|
||||||
|
|
||||||
constructor(context) {
|
constructor(context:common.UIAbilityContext) {
|
||||||
(async () => {
|
(async () => {
|
||||||
const fileUtil = new FileUtils(context)
|
const fileUtil = new FileUtils(context)
|
||||||
this.fileUtil = fileUtil
|
this.fileUtil = fileUtil
|
||||||
@ -23,31 +29,31 @@ export default class FileModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 存储zip文件并解压
|
// 存储zip文件并解压
|
||||||
public storingFiles = async (str) => {
|
public storingFiles = async (str:string) => {
|
||||||
const { fileUtil, folderPath } = this;
|
await this.fileUtil.editFile(`${this.folderPath}/model.zip`, str)
|
||||||
await fileUtil.editFile(`${folderPath}/model.zip`, str)
|
|
||||||
|
|
||||||
let options = {
|
const folderPath = this.folderPath
|
||||||
|
let options:Options = {
|
||||||
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
|
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
|
||||||
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
|
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
|
||||||
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
|
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
|
||||||
};
|
};
|
||||||
|
|
||||||
zlib.unzipFile(
|
try {
|
||||||
`${folderPath}/model.zip`,
|
zlib.unzipFile(
|
||||||
`${folderPath}`,
|
`${folderPath}/model.zip`,
|
||||||
options).then((data) => {
|
`${folderPath}`,
|
||||||
console.log("unzipFile result:" + data);
|
options).then((data) => {
|
||||||
}).catch((err) => {
|
console.log("unzipFile result:" + data);
|
||||||
|
})
|
||||||
|
}catch (err) {
|
||||||
console.log("catch((err)=>" + err);
|
console.log("catch((err)=>" + err);
|
||||||
})
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//获取文件内容
|
//获取文件内容
|
||||||
public getModelContent = (folderPath, fileName) => {
|
public getModelContent = (folderPath:string, fileName:string) => {
|
||||||
const { fileUtil } = this;
|
|
||||||
try {
|
try {
|
||||||
const content = fileUtil.getFileContent(`${folderPath}/${fileName}`)
|
const content = this.fileUtil.getFileContent(`${folderPath}/${fileName}`)
|
||||||
return content;
|
return content;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info('surenjun', JSON.stringify(e))
|
console.info('surenjun', JSON.stringify(e))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user