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