| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 12-May-2024 | - | 36 | 33 | ||
| entry/ | 12-May-2024 | - | 1,284 | 1,166 | ||
| hvigor/ | 12-May-2024 | - | 24 | 22 | ||
| screenshots/device/ | 12-May-2024 | - | ||||
| .gitignore | D | 12-May-2024 | 121 | 10 | 10 | |
| README.md | D | 12-May-2024 | 1.3 KiB | 36 | 18 | |
| README_zh.md | D | 12-May-2024 | 2.5 KiB | 73 | 48 | |
| build-profile.json5 | D | 12-May-2024 | 1 KiB | 42 | 41 | |
| hvigorfile.ts | D | 12-May-2024 | 158 | 2 | 1 | |
| hvigorw | D | 12-May-2024 | 2.1 KiB | 62 | 28 | |
| hvigorw.bat | D | 12-May-2024 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 12-May-2024 | 812 | 27 | 25 | |
| ohosTest.md | D | 12-May-2024 | 696 | 7 | 7 |
README.md
1# Zip and Unzip 2 3### Introduction 4 5This sample demonstrates the use of @ohos.zlib. Below shows the sample app. 6 7 8 9### Concepts 10 11Zip: compresses a file or folder based on the passed file path to zip and the path of the zipped file. 12 13Unzip: decompresses a file or folder based on the passed file path to unzip and the path of the unzipped file. 14 15### Required Permissions 16 17N/A 18 19### Usage 20 211. Touch **+** in the upper right corner of the sample app. 22 232. In the **Create file** dialog box displayed, enter the file name and content, and touch **OK**. 24 253. The file created is displayed on the home page. Touch **Zip**. A message is displayed, indicating that the file is compressed, and a **.zip** file with the same name is created in the file list. 26 274. Touch **Unzip** next to the zipped file. A message is displayed, indicating that the file is decompressed, and a folder with the same name is created in the file list. 28 29### Constraints 30 311. This sample can only be run on standard-system devices. 32 332. This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100, built on November 3, 2022) to compile and run. 34 353. The paths passed in the `Zip` and `Unzip` APIs must be the relative paths obtained by the context API. Currently, `Zip` and `Unzip` support operations only on files in the app directory. 36
README_zh.md
1# 压缩与解压 2 3### 介绍 4 5本示例通过[@ohos.zlib](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-zlib.md) 6和[@ohos.fileio](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileio.md) 接口,实现添加文件、解压和压缩文件场景。 7 8### 效果预览 9 10|主页|新建弹窗| 11|---|---| 12||| 13 14使用说明 15 161.点击屏幕右上角 **+** 按钮,弹出创建文件窗口; 17 182.输入文件名称、文件内容,并点击 **确定** 按钮来创建文件; 19 203.文件创建成功后,文件名称自动追加.txt后缀并在主页面列表会显示,同时文件的物理地址为/data/app/el2/100/base/ohos.samples.ziplib/haps/entry/files/,点击 **压缩** 按钮,提示“文件压缩成功”,并会在文件列表创建一个相同名称的.zip文件; 21 224.点击压缩文件后的 **解压** 按钮,提示“文件解压成功”,并会再次在文件列表创建一个同名文件夹。 23 24### 工程目录 25 26``` 27entry/src/main/ets/ 28|---common 29| |---AddDialog.ets // 弹窗组件 30|---entryability 31|---model 32| |---DataSource.ets // 懒加载文件 33| |---Logger.ets // 日志文件 34|---pages 35| |---Index.ets // 首页,接口都在这里调用 36``` 37 38### 具体实现 39 40* 添加文件、解压和压缩文件的接口都在首页调用,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) 41 * 添加文件:通过调用fileio.openSync()创建文件并调用fileio.writeSync()向文件中写入内容; 42 * 压缩文件:通过调用zlib.zipFile()压缩文件; 43 * 解压文件:通过zlib.unzipFile解压文件。 44 45### 相关权限 46 47不涉及。 48 49### 依赖 50 51不涉及。 52 53### 约束与限制 54 551.本示例仅支持在标准系统上运行。 56 572.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)才可编译运行。 58 593.解压与压缩相关接口的入参路径必须为context相关接口获取的相对路径,目前该接口仅支持操作应用目录下的文件。 60 614.本示例已适配API version 9版本SDK,版本号:3.2.11.9。 62 63### 下载 64 65如需单独下载本工程,执行如下命令: 66 67``` 68git init 69git config core.sparsecheckout true 70echo code/LaunguageBaseClassLibrary/ZipLib/ > .git/info/sparse-checkout 71git remote add origin https://gitee.com/openharmony/applications_app_samples.git 72git pull origin master 73```