diff --git a/zh-cn/application-dev/reference/apis/js-apis-zlib.md b/zh-cn/application-dev/reference/apis/js-apis-zlib.md
index 8138283e12eac6f85872a718f035bf00670afb64..3c85311c4ba3748b49b6d4ce1764531a94f26dcc 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-zlib.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-zlib.md
@@ -13,7 +13,7 @@ import zlib from '@ohos.zlib';
```
## zlib.zipFile(deprecated)
- zipFile(inFile:string, outFile:string, options: Options): Promise<void>
+zipFile(inFile: string, outFile: string, options: Options): Promise<void>
压缩接口(Promise形式)。
@@ -26,7 +26,7 @@ import zlib from '@ohos.zlib';
| 参数名 | 类型 | 必填 | 描述 |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | 是 | 指定压缩的文件夹路径或者文件路径,对应的路径参考[FA模型](js-apis-Context.md),[Stage模型](js-apis-application-context.md) |
-| outFile | string | 是 | 指定的压缩结果的文件路径(文件的扩展名zip) |
+| outFile | string | 是 | 指定压缩结果的文件路径(文件的扩展名zip) |
| options | [Options](#options) | 否 | 压缩的可选参数 |
**返回值:**
@@ -37,43 +37,41 @@ import zlib from '@ohos.zlib';
**示例1:**
-```javascript
-
+```typescript
//【压缩文件 例子1】
-import zlib from '@ohos.zlib'
-var inFile = "/xxx/filename.xxx";
-var outFile = "/xxx/xxx.zip";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xxx/filename.xxx';
+let outFile = '/xxx/xxx.zip';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.zipFile(inFile, outFile, options).then((data) => {
- console.log("zipFile result:" + data);
-}).catch((err)=>{
- console.log("catch((err)=>" + err);
+ console.log('zipFile result is ' + JSON.Stringify(data));
+}).catch((err) => {
+ console.log('error is ' + JSON.Stringify(err));
});
-
```
**示例2:**
-```
+```typescript
// 【压缩文件夹 例子2】
-import zlib from '@ohos.zlib'
-var inFile = "/xxx/xxx";
-var outFile = "/xxx/xxx.zip";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xxx/xxx';
+let outFile = '/xxx/xxx.zip';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.zipFile(inFile , outFile, options).then((data) => {
- console.log("zipFile result:" + data);
+ console.log('zipFile result is ' + JSON.Stringify(data));
}).catch((err)=>{
- console.log("catch((err)=>" + err);
+ console.log('error is ' + JSON.Stringify(err));
});
```
@@ -103,11 +101,11 @@ unzipFile(inFile:string, outFile:string, options: Options): Promise<void>
**示例:**
-```javascript
-// 【解压例子1】
-import zlib from '@ohos.zlib'
-var inFile = "/xx/xxx.zip";
-var outFile = "/xxx";
+```typescript
+// 【解压缩 例子1】
+import zlib from '@ohos.zlib';
+let inFile = '/xx/xxx.zip';
+let outFile = '/xxx';
let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
@@ -115,16 +113,15 @@ let options = {
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.unzipFile(inFile, outFile, options).then((data) => {
- console.log("unzipFile result:" + data);
+ console.log('unzipFile result is ' + JSON.Stringify(data));
}).catch((err)=>{
- console.log("catch((err)=>" + err);
+ console.log('error is ' + JSON.Stringify(err));
})
-
```
## zlib.compressFile9+
-**function** compressFile(inFile: **string**, outFile: **string**, options: Options, callback: AsyncCallback<**void**>): **void**;
+compressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback\): void;
压缩文件,压缩的结果通过callback返回。成功时返回null,失败时返回错误码。
@@ -149,13 +146,13 @@ zlib.unzipFile(inFile, outFile, options).then((data) => {
**示例**
-```javascript
-// 【压缩例子1】
+```typescript
+// 【压缩文件 例子1】
// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取
-import zlib from '@ohos.zlib'
-var inFile = "/xxx/filename.xxx";
-var outFile = "/xxx/xxx.zip";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xxx/filename.xxx';
+let outFile = '/xxx/xxx.zip';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
@@ -163,16 +160,16 @@ var options = {
try {
zlib.compressFile(inFile, outFile, options, (errData) => {
- if (erData != null) {
- console.log("errData is " + errData.errCode + " " + errData.message)
+ if (erData !== null) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
}
})
-} catch(errData => {
- console.log("catch err " + errData.errCode + " " + errData.message)
-})
+} catch(errData) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
+}
```
-**function** compressFile(inFile:**string**, outFile:**string**, options: Options): Promise<**void**>;
+compressFile(inFile: string, outFile: string, options: Options): Promise\;
压缩文件,压缩的结果通过promise返回,成功时返回null,失败时返回错误码。
@@ -180,12 +177,11 @@ try {
**参数:**
-| 参数名 | 类型 | 必填 | 描述 |
-| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
-| inFile | string | 是 | 指定压缩的文件夹路径或者文件路径,对应的路径参考[FA模型](js-apis-Context.md),[stage模型](js-apis-application-context.md) |
-| outFile | string | 是 | 指定的解压文件路径 |
-| options | [Options](#options) | 是 | 压缩的配置参数 |
-| AsyncCallback<**void**> | callback | 否 | 压缩时的回调函数 |
+| 参数名 | 类型 | 必填 | 描述 |
+| ------- | ------------------- | ---- | ------------------------------------------------------------ |
+| inFile | string | 是 | 指定压缩的文件夹路径或者文件路径,对应的路径参考[FA模型](js-apis-Context.md),[stage模型](js-apis-application-context.md) |
+| outFile | string | 是 | 指定的解压文件路径 |
+| options | [Options](#options) | 是 | 压缩的配置参数 |
**相关错误码**
@@ -195,37 +191,39 @@ try {
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
-```javascript
-// 【压缩例子2】
+```typescript
+// 【压缩文件 例子2】
// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取
-import zlib from '@ohos.zlib'
-var inFile = "/xxx/filename.xxx";
-var outFile = "/xxx/xxx.zip";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xxx/filename.xxx';
+let outFile = '/xxx/xxx.zip';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
try {
- zlib.compressFile(inFile, outFile, options).then(data => {
- console.info("compressFile success")
- }).catch(errData => {
- console.info("catch err " + errData.errCode + " " + errData.message)
+ zlib.compressFile(inFile, outFile, options).then((data) => {
+ console.info('compressFile success');
+ }).catch((errData) => {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
})
-} catch(errData => {
- console.log("catch err " + errData.errCode + " " + errData.message)
-})
+} catch(errData) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
+}
```
## zlib.decompressFile9+
-**function** decompressFile(inFile: **string**, outFile: **string**, options: Options, callback: AsyncCallback<**void**>): **void**;
+decompressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback\): void;
解压文件,解压的结果通过callback返回,成功时返回null,失败时返回错误码。
+**系统能力:** SystemCapability.BundleManager.Zlib
+
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
@@ -245,32 +243,35 @@ try {
**示例**
-```javascript
-// 【解压缩例子1】
+```typescript
+// 【解压缩 例子1】
// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取
-import zlib from '@ohos.zlib'
-var inFile = "/xx/xxx.zip";
-var outFile = "/xxx";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xx/xxx.zip';
+let outFile = '/xxx';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
+
try {
zlib.decompressFile(inFile, outFile, options, (errData) => {
- if (erData != null) {
- console.log("errData is " + errData.errCode + " " + errData.message)
+ if (erData !== null) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
}
})
-} catch(errData => {
- console.log("catch err " + errData.errCode + " " + errData.message)
-})
+} catch(errData) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
+}
```
-**function** decompressFile(inFile: **string**, outFile: **string**, options: Options): Promise<**void**>;
+decompressFile(inFile: string, outFile: string, options: Options): Promise\;
解压文件,解压的结果通过promise返回,成功时返回null,失败时返回错误码。
+**系统能力:** SystemCapability.BundleManager.Zlib
+
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
@@ -287,26 +288,27 @@ try {
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
-```javascript
-// 【解压缩例子2】
+```typescript
+// 【解压缩 例子2】
// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取
-import zlib from '@ohos.zlib'
-var inFile = "/xx/xxx.zip";
-var outFile = "/xxx";
-var options = {
+import zlib from '@ohos.zlib';
+let inFile = '/xx/xxx.zip';
+let outFile = '/xxx';
+let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
+
try {
- zlib.compressFile(inFile, outFile, options).then(data => {
- console.info("compressFile success")
- }).catch(errData => {
- console.info("catch err " + errData.errCode + " " + errData.message)
+ zlib.deCompressFile(inFile, outFile, options).then((data) => {
+ console.info('deCompressFile success');
+ }).catch((errData) => {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
})
-} catch(errData => {
- console.log("catch err " + errData.errCode + " " + errData.message)
-})
+} catch(errData) {
+ console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
+}
```
## Options
@@ -319,16 +321,6 @@ try {
| memLevel | MemLevel | 否 | 参考[zip.MemLevel枚举定义](#zipmemlevel) |
| strategy | CompressStrategy | 否 | 参考[zip.CompressStrategy枚举定义](#zipcompressstrategy) |
-## zip.MemLevel
-
-**系统能力:** SystemCapability.BundleManager.Zlib
-
-| 名称 | 值 | 说明 |
-| ----------------- | ---- | -------------------------------- |
-| MEM_LEVEL_MIN | 1 | zip 接口在压缩过程中最小使用内存 |
-| MEM_LEVEL_MAX | 9 | zip 接口在压缩过程中最大使用内存 |
-| MEM_LEVEL_DEFAULT | 8 | zip 接口在压缩过程中默认使用内存 |
-
## zip.CompressLevel
**系统能力:** SystemCapability.BundleManager.Zlib
@@ -340,6 +332,16 @@ try {
| COMPRESS_LEVEL_BEST_COMPRESSION | 9 | 最佳压缩等级 |
| COMPRESS_LEVEL_DEFAULT_COMPRESSION | -1 | 默认压缩等级 |
+## zip.MemLevel
+
+**系统能力:** SystemCapability.BundleManager.Zlib
+
+| 名称 | 值 | 说明 |
+| ----------------- | ---- | -------------------------------- |
+| MEM_LEVEL_MIN | 1 | zip 接口在压缩过程中最小使用内存 |
+| MEM_LEVEL_MAX | 9 | zip 接口在压缩过程中最大使用内存 |
+| MEM_LEVEL_DEFAULT | 8 | zip 接口在压缩过程中默认使用内存 |
+
## zip.CompressStrategy
**系统能力:** SystemCapability.BundleManager.Zlib
diff --git a/zh-cn/application-dev/reference/errorcodes/errorcodes-zlib.md b/zh-cn/application-dev/reference/errorcodes/errorcode-zlib.md
similarity index 83%
rename from zh-cn/application-dev/reference/errorcodes/errorcodes-zlib.md
rename to zh-cn/application-dev/reference/errorcodes/errorcode-zlib.md
index 559f2ba4a7e76e966212fc53bb96e88270e1c09a..d7038b823654fdaa4601f053f7f808a006113e46 100755
--- a/zh-cn/application-dev/reference/errorcodes/errorcodes-zlib.md
+++ b/zh-cn/application-dev/reference/errorcodes/errorcode-zlib.md
@@ -16,7 +16,8 @@ The input source file is invalid.
**处理步骤**
-检查源文件是否存在。
+1. 检查源文件是否存在。
+2. 检查待压缩的文件路径是否存在,并且路径是否在正确的沙箱路径下。
## 900002 传入的目标文件错误