未验证 提交 e98076df 编写于 作者: O openharmony_ci 提交者: Gitee

!17857 翻译完成:16930 fix error code for zip and unzip

Merge pull request !17857 from wusongqing/TR16930
......@@ -25,7 +25,7 @@ Zips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the zipped file. The file name extension is .zip. |
| options | [Options](#options) | Yes | Optional parameters for the zip operation. |
......@@ -50,9 +50,9 @@ let options = {
};
zlib.zipFile(inFile, outFile, options).then((data) => {
console.log('zipFile result is ' + JSON.Stringify(data));
console.log('zipFile result is ' + JSON.stringify(data));
}).catch((err) => {
console.log('error is ' + JSON.Stringify(err));
console.log('error is ' + JSON.stringify(err));
});
```
......@@ -71,9 +71,9 @@ let options = {
};
zlib.zipFile(inFile , outFile, options).then((data) => {
console.log('zipFile result is ' + JSON.Stringify(data));
console.log('zipFile result is ' + JSON.stringify(data));
}).catch((err)=>{
console.log('error is ' + JSON.Stringify(err));
console.log('error is ' + JSON.stringify(err));
});
```
......@@ -91,7 +91,7 @@ Unzips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to unzip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to unzip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the unzipped file. |
| options | [Options](#options) | Yes | Optional parameters for the unzip operation. |
......@@ -116,9 +116,9 @@ let options = {
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.unzipFile(inFile, outFile, options).then((data) => {
console.log('unzipFile result is ' + JSON.Stringify(data));
console.log('unzipFile result is ' + JSON.stringify(data));
}).catch((err)=>{
console.log('error is ' + JSON.Stringify(err));
console.log('error is ' + JSON.stringify(err));
})
```
......@@ -134,7 +134,7 @@ Compresses a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
......@@ -172,6 +172,8 @@ try {
}
```
## zlib.compressFile<sup>9+</sup>
compressFile(inFile: string, outFile: string, options: Options): Promise\<void>;
Compresses a file. This API uses a promise to return the result.
......@@ -182,7 +184,7 @@ Compresses a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. |
......@@ -232,9 +234,9 @@ Decompresses a file. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. |
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| options | [Options](#options) | Yes | Decompression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
**Error codes**
......@@ -253,7 +255,7 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip';
let outFile = '/xxx';
let outFileDir = '/xxx';
let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
......@@ -261,7 +263,7 @@ let options = {
};
try {
zlib.decompressFile(inFile, outFile, options, (errData) => {
zlib.decompressFile(inFile, outFileDir, options, (errData) => {
if (errData !== null) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
......@@ -271,6 +273,8 @@ try {
}
```
## zlib.decompressFile<sup>9+</sup>
decompressFile(inFile: string, outFile: string, options: Options): Promise\<void>;
Decompresses a file. This API uses a promise to return the result.
......@@ -281,9 +285,9 @@ Decompresses a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. |
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| options | [Options](#options) | Yes | Decompression parameters. |
**Error codes**
......@@ -299,7 +303,7 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip';
let outFile = '/xxx';
let outFileDir = '/xxx';
let options = {
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
......@@ -307,7 +311,7 @@ let options = {
};
try {
zlib.decompressFile(inFile, outFile, options).then((data) => {
zlib.decompressFile(inFile, outFileDir, options).then((data) => {
console.info('decompressFile success');
}).catch((errData) => {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册