| 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 | 72 | 47 | |
| 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)和[@ohos.fileio](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileio.md) 接口,实现添加文件、解压和压缩文件场景。 6 7### 效果预览 8 9|主页|新建弹窗| 10|---|---| 11||| 12 13使用说明 14 151.点击屏幕右上角 **+** 按钮,弹出创建文件窗口; 16 172.输入文件名称、文件内容,并点击 **确定** 按钮来创建文件; 18 193.文件创建成功后,文件名称自动追加.txt后缀并在主页面列表会显示,同时文件的物理地址为/data/app/el2/100/base/ohos.samples.ziplib/haps/entry/files/,点击 **压缩** 按钮,提示“文件压缩成功”,并会在文件列表创建一个相同名称的.zip文件; 20 214.点击压缩文件后的 **解压** 按钮,提示“文件解压成功”,并会再次在文件列表创建一个同名文件夹。 22 23### 工程目录 24 25``` 26entry/src/main/ets/ 27|---common 28| |---AddDialog.ets // 弹窗组件 29|---entryability 30|---model 31| |---DataSource.ets // 懒加载文件 32| |---Logger.ets // 日志文件 33|---pages 34| |---Index.ets // 首页,接口都在这里调用 35``` 36 37### 具体实现 38 39* 添加文件、解压和压缩文件的接口都在首页调用,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) 40 * 添加文件:通过调用fileio.openSync()创建文件并调用fileio.writeSync()向文件中写入内容; 41 * 压缩文件:通过调用zlib.zipFile()压缩文件; 42 * 解压文件:通过zlib.unzipFile解压文件。 43 44### 相关权限 45 46不涉及。 47 48### 依赖 49 50不涉及。 51 52### 约束与限制 53 541.本示例仅支持在标准系统上运行。 55 562.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)才可编译运行。 57 583.解压与压缩相关接口的入参路径必须为context相关接口获取的相对路径,目前该接口仅支持操作应用目录下的文件。 59 604.本示例已适配API version 9版本SDK,版本号:3.2.11.9。 61 62### 下载 63 64如需单独下载本工程,执行如下命令: 65 66``` 67git init 68git config core.sparsecheckout true 69echo code/LaunguageBaseClassLibrary/ZipLib/ > .git/info/sparse-checkout 70git remote add origin https://gitee.com/openharmony/applications_app_samples.git 71git pull origin master 72```