提交 69d65dc3 编写于 作者: W wusongqing

update docs against 5894

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 06f612dc
# Bundle Module (JavaScript SDK APIs) # Bundle
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> API version 9 is a canary version for trial use. The APIs of this version may be unstable. > API version 9 is a canary version for trial use. The APIs of this version may be unstable.
## Modules to Import ## Modules to Import
...@@ -15,11 +16,11 @@ SystemCapability.BundleManager.BundleFramework ...@@ -15,11 +16,11 @@ SystemCapability.BundleManager.BundleFramework
## Required Permissions ## Required Permissions
| Required Permissions | Permission Level | Description | | Required Permissions | Permission Level | Description |
| ---------------------------------------- | ------------ | --------- | | ------------------------------------------ | ------------ | ------------------ |
| ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about the current application.| | ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about the current application. |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all applications.| | ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all applications.|
| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall applications. | | ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall applications. |
## bundle.getApplicationInfo ## bundle.getApplicationInfo
...@@ -69,7 +70,7 @@ bundle.getApplicationInfo(bundleName, bundleFlags, userId) ...@@ -69,7 +70,7 @@ bundle.getApplicationInfo(bundleName, bundleFlags, userId)
getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<ApplicationInfo>): void getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<ApplicationInfo>): void
Obtains the application information based on a given bundle name. This API uses an asynchronous callback to return the result. Obtains the application information of the specified user based on a given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions** **Required permissions**
...@@ -143,9 +144,9 @@ bundle.getApplicationInfo(bundleName, bundleFlags, (err, data) => { ...@@ -143,9 +144,9 @@ bundle.getApplicationInfo(bundleName, bundleFlags, (err, data) => {
## bundle.getAllBundleInfo ## bundle.getAllBundleInfo
getAllBundleInfo(bundleFlag: BundleFlag, userId?: number): Promise\<Array\<BundleInfo>> getAllBundleInfo(bundleFlag: BundleFlag, userId?: number): Promise<Array\<BundleInfo>>
Obtains the information of all available bundles of a specified user in the system. This API uses a promise to return the result. Obtains the information of all available bundles of the specified user in the system. This API uses a promise to return the result.
**Required permissions** **Required permissions**
...@@ -166,7 +167,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -166,7 +167,7 @@ SystemCapability.BundleManager.BundleFramework
| Type | Description | | Type | Description |
| --------------------------- | -------------------------- | | --------------------------- | -------------------------- |
| Promise\<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Promise used to return the information of all available bundles.| | Promise<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Promise used to return the information of all available bundles.|
**Example** **Example**
...@@ -185,7 +186,7 @@ bundle.getAllBundleInfo(bundleFlag, userId) ...@@ -185,7 +186,7 @@ bundle.getAllBundleInfo(bundleFlag, userId)
## bundle.getAllBundleInfo ## bundle.getAllBundleInfo
getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback\<Array\<BundleInfo>>): void getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array\<BundleInfo>>): void
Obtains the information of all available bundles in the system. This API uses an asynchronous callback to return the result. Obtains the information of all available bundles in the system. This API uses an asynchronous callback to return the result.
...@@ -220,9 +221,9 @@ bundle.getAllBundleInfo(bundleFlag, (err, data) => { ...@@ -220,9 +221,9 @@ bundle.getAllBundleInfo(bundleFlag, (err, data) => {
## bundle.getAllBundleInfo ## bundle.getAllBundleInfo
getAllBundleInfo(bundleFlag: BundleFlag, userId: number, callback: AsyncCallback\<Array\<BundleInfo>>): void getAllBundleInfo(bundleFlag: BundleFlag, userId: number, callback: AsyncCallback<Array\<BundleInfo>>): void
Obtains the information of all available bundles in the system. This API uses an asynchronous callback to return the result. Obtains the information of all available bundles of the specified user in the system. This API uses an asynchronous callback to return the result.
**Required permissions** **Required permissions**
...@@ -238,7 +239,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -238,7 +239,7 @@ SystemCapability.BundleManager.BundleFramework
| ---------- | --------------------------------- | ---- | --------------------------------------- | | ---------- | --------------------------------- | ---- | --------------------------------------- |
| bundleFlag | BundleFlag | Yes | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.| | bundleFlag | BundleFlag | Yes | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. | | userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback\<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Yes | Callback used to return the information of all available bundles. | | callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Yes | Callback used to return the information of all available bundles. |
**Example** **Example**
...@@ -343,7 +344,7 @@ bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => { ...@@ -343,7 +344,7 @@ bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => {
getBundleInfo(bundleName: string, bundleFlags: number, options: BundleOptions, callback: AsyncCallback\<BundleInfo>): void getBundleInfo(bundleName: string, bundleFlags: number, options: BundleOptions, callback: AsyncCallback\<BundleInfo>): void
Obtains the bundle information based on a given bundle name. This API uses an asynchronous callback to return the result. Obtains the bundle information based on a given bundle name and bundle options. This API uses an asynchronous callback to return the result.
**Required permissions** **Required permissions**
...@@ -718,10 +719,6 @@ isAbilityEnabled(info: AbilityInfo): Promise\<boolean> ...@@ -718,10 +719,6 @@ isAbilityEnabled(info: AbilityInfo): Promise\<boolean>
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses a promise to return the result. Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses a promise to return the result.
**Required permissions**
None
**System capability** **System capability**
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
...@@ -759,10 +756,6 @@ isAbilityEnabled(info : AbilityInfo, callback : AsyncCallback\<boolean>): void ...@@ -759,10 +756,6 @@ isAbilityEnabled(info : AbilityInfo, callback : AsyncCallback\<boolean>): void
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses an asynchronous callback to return the result. Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses an asynchronous callback to return the result.
**Required permissions**
None
**System capability** **System capability**
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
...@@ -796,10 +789,6 @@ isApplicationEnabled(bundleName: string): Promise\<boolean> ...@@ -796,10 +789,6 @@ isApplicationEnabled(bundleName: string): Promise\<boolean>
Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result. Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result.
**Required permissions**
None
**System capability** **System capability**
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
...@@ -834,10 +823,6 @@ isApplicationEnabled(bundleName: string, callback : AsyncCallback\<boolean>): vo ...@@ -834,10 +823,6 @@ isApplicationEnabled(bundleName: string, callback : AsyncCallback\<boolean>): vo
Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result. Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**
None
**System capability** **System capability**
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
...@@ -911,9 +896,13 @@ bundle.queryAbilityByWant(want, bundleFlags, userId) ...@@ -911,9 +896,13 @@ bundle.queryAbilityByWant(want, bundleFlags, userId)
## bundle.queryAbilityByWant ## bundle.queryAbilityByWant
queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback\<Array\<AbilityInfo>>): void queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array\<AbilityInfo>>): void
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result. Obtains the ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
...@@ -923,7 +912,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -923,7 +912,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----------- | ---------------------------------- | ---- | ------------------------------------- | | ----------- | ---------------------------------- | ---- | ------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.| | bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. | | userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. | | callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
...@@ -952,6 +941,10 @@ queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Arra ...@@ -952,6 +941,10 @@ queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Arra
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result. Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
...@@ -960,7 +953,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -960,7 +953,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----------- | ---------------------------------- | ---- | ------------------------------------- | | ----------- | ---------------------------------- | ---- | ------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.| | bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. | | callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
...@@ -1127,7 +1120,7 @@ Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bu ...@@ -1127,7 +1120,7 @@ Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bu
**Required permissions** **Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
...@@ -1166,7 +1159,7 @@ Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bu ...@@ -1166,7 +1159,7 @@ Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bu
**Required permissions** **Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
...@@ -1203,7 +1196,7 @@ Obtains the Extension ability information based on a given want. This API uses a ...@@ -1203,7 +1196,7 @@ Obtains the Extension ability information based on a given want. This API uses a
**Required permissions** **Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
...@@ -1214,7 +1207,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -1214,7 +1207,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------- | ------ | ---- | ---------------------------------------- | | -------------- | ------ | ---- | ---------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.| | extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#ExtensionFlag9).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. | | userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value** **Return value**
...@@ -1246,11 +1239,11 @@ bundle.queryExtensionAbilityInfosByWant(want, extensionFlags, userId) ...@@ -1246,11 +1239,11 @@ bundle.queryExtensionAbilityInfosByWant(want, extensionFlags, userId)
queryExtensionAbilityInfosByWant(want: Want, extensionFlags: number, userId: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void queryExtensionAbilityInfosByWant(want: Want, extensionFlags: number, userId: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void
Obtains the Extension ability information based on a given want. This API uses an asynchronous callback to return the result. Obtains the Extension ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions** **Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability** **System capability**
...@@ -1258,12 +1251,12 @@ SystemCapability.BundleManager.BundleFramework ...@@ -1258,12 +1251,12 @@ SystemCapability.BundleManager.BundleFramework
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.| | extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#ExtensionFlag9). |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. | | userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. | | callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. |
**Example** **Example**
...@@ -1301,8 +1294,8 @@ SystemCapability.BundleManager.BundleFramework ...@@ -1301,8 +1294,8 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.| | extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#ExtensionFlag9). |
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. | | callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. |
**Example** **Example**
...@@ -1369,7 +1362,7 @@ Enumerates bundle flags. ...@@ -1369,7 +1362,7 @@ Enumerates bundle flags.
| GET_ABILITY_INFO_SYSTEMAPP_ONLY<sup>8+</sup> | 0x00000080 | Obtains the ability information of system applications.| | GET_ABILITY_INFO_SYSTEMAPP_ONLY<sup>8+</sup> | 0x00000080 | Obtains the ability information of system applications.|
| GET_ABILITY_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000100 | Obtains information about disabled abilities. | | GET_ABILITY_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000100 | Obtains information about disabled abilities. |
| GET_APPLICATION_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000200 | Obtains information about disabled applications. | | GET_APPLICATION_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000200 | Obtains information about disabled applications. |
| GET_ALL_APPLICATION_INFO | 0xFFFF0000 | Obtains all application information. | | GET_ALL_APPLICATION_INFO | 0xFFFF0000 | Obtains all application information. |
## BundleOptions ## BundleOptions
...@@ -1403,10 +1396,10 @@ Enumerates display orientations. ...@@ -1403,10 +1396,10 @@ Enumerates display orientations.
| Name | Type | Description | | Name | Type | Description |
| ------------- | ---- | ------------- | | ------------- | ---- | ------------- |
| UNSPECIFIED | None | The system automatically determines the display orientation. | | UNSPECIFIED | None | Unspecified display orientation. |
| LANDSCAPE | None | Landscape orientation. | | LANDSCAPE | None | Landscape orientation. |
| PORTRAIT | None | Portrait orientation. | | PORTRAIT | None | Portrait orientation. |
| FOLLOW_RECENT | None | The page ability orientation is the same as that of the nearest ability in the stack.| | FOLLOW_RECENT | None | Orientation same as that of the nearest ability in the stack.|
## LaunchMode ## LaunchMode
...@@ -1438,7 +1431,7 @@ Enumerates Extension ability types. ...@@ -1438,7 +1431,7 @@ Enumerates Extension ability types.
| Name | Type | Description | | Name | Type | Description |
| ------------------------------ | ---- | ------------------------- | | ------------------------------ | ---- | ------------------------- |
| FORM<sup>9+</sup> | 0 | Form included. | | FORM<sup>9+</sup> | 0 | Form (widget) included. |
| WORK_SCHEDULER<sup>9+</sup> | 1 | Work scheduler included.| | WORK_SCHEDULER<sup>9+</sup> | 1 | Work scheduler included.|
| INPUT_METHOD<sup>9+</sup> | 2 | Input method included. | | INPUT_METHOD<sup>9+</sup> | 2 | Input method included. |
| SERVICE<sup>9+</sup> | 3 | Service included. | | SERVICE<sup>9+</sup> | 3 | Service included. |
...@@ -1484,3 +1477,4 @@ Enumerates permission grant states. ...@@ -1484,3 +1477,4 @@ Enumerates permission grant states.
| ------------------ | ---- | ---- | | ------------------ | ---- | ---- |
| PERMISSION_DENIED | -1 | Permission denied.| | PERMISSION_DENIED | -1 | Permission denied.|
| PERMISSION_GRANTED | 0 | Permission granted. | | PERMISSION_GRANTED | 0 | Permission granted. |
# Zip # Zip
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Constraints ## Constraints
None None
## Modules to Import ## Modules to Import
...@@ -9,18 +14,19 @@ import zlib from '@ohos.zlib'; ...@@ -9,18 +14,19 @@ import zlib from '@ohos.zlib';
``` ```
## zlib.zipFile ## zlib.zipFile
zipFile(inFile:string, outFile:string, options: Options): Promise\<void> zipFile(inFile:string, outFile:string, options: Options): Promise&lt;void&gt;
Zips a file. This API uses a promise to return the result. Zips a file. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.Zlib **System capability**: SystemCapability.BundleManager.Zlib
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------------------------------- | ---- | ------------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to zip. | | inFile | string | Yes | Path of the folder or file to zip. For details about the path, see [FA Model](js-apis-Context.md) and [Stage Model](js-apis-application-context.md).|
| outFile | string | Yes | Path of the zipped file. The file name extension is .zip.| | outFile | string | Yes | Path of the zipped file. The file name extension is .zip. |
| options | [Options](#options)| No | Optional parameters for the zip operation. | | options | [Options](#options) | No | Optional parameters for the zip operation. |
**Return value** **Return value**
...@@ -36,17 +42,14 @@ Zips a file. This API uses a promise to return the result. ...@@ -36,17 +42,14 @@ Zips a file. This API uses a promise to return the result.
import zlib from '@ohos.zlib' import zlib from '@ohos.zlib'
var inFile = "/xxx/filename.xxx"; var inFile = "/xxx/filename.xxx";
var outFile = "/xxx/xxx.zip"; var outFile = "/xxx/xxx.zip";
var options = {}; var options = {
options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION; level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
options.memLevel = zlib.MemLevel.MEM_LEVEL_DEFAULT; memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY; strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.zipFile(inFile, outFile, options).then((data) => { zlib.zipFile(inFile, outFile, options).then((data) => {
if (data == zlib.ErrorCode.ERROR_CODE_OK) { console.log("zipFile result: " + data);
console.log("zipFile OK");
} else {
console.log("zipFile NG");
}
}).catch((err)=>{ }).catch((err)=>{
console.log("catch((err)=>" + err); console.log("catch((err)=>" + err);
}); });
...@@ -60,17 +63,14 @@ zlib.zipFile(inFile, outFile, options).then((data) => { ...@@ -60,17 +63,14 @@ zlib.zipFile(inFile, outFile, options).then((data) => {
import zlib from '@ohos.zlib' import zlib from '@ohos.zlib'
var inFile = "/xxx/xxx"; var inFile = "/xxx/xxx";
var outFile = "/xxx/xxx.zip"; var outFile = "/xxx/xxx.zip";
var options = {}; var options = {
options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION; level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
options.memLevel = zlib.MemLevel.MEM_LEVEL_DEFAULT; memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY; strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.zipFile(inFile , unzipDir, options).then((data) => {
if (data == zlib.ErrorCode.ERROR_CODE_OK) { zlib.zipFile(inFile , outFile, options).then((data) => {
console.log("zipFile OK"); console.log("zipFile result: " + data);
} else {
console.log("zipFile NG");
}
}).catch((err)=>{ }).catch((err)=>{
console.log("catch((err)=>" + err); console.log("catch((err)=>" + err);
}); });
...@@ -78,7 +78,7 @@ zlib.zipFile(inFile , unzipDir, options).then((data) => { ...@@ -78,7 +78,7 @@ zlib.zipFile(inFile , unzipDir, options).then((data) => {
## zlib.unzipFile ## zlib.unzipFile
unzipFile(inFile:string, outFile:string, options: Options): Promise\<void> unzipFile(inFile:string, outFile:string, options: Options): Promise&lt;void&gt;
Unzips a file. This API uses a promise to return the result. Unzips a file. This API uses a promise to return the result.
...@@ -86,11 +86,11 @@ Unzips a file. This API uses a promise to return the result. ...@@ -86,11 +86,11 @@ Unzips a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------------------------------- | ---- | ----------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to unzip. The file name extension is .zip.| | inFile | string | Yes | Path of the folder or file to zip. For details about the path, see [FA Model](js-apis-Context.md) and [Stage Model](js-apis-application-context.md).|
| outFile | string | Yes | Path of the unzipped file. | | outFile | string | Yes | Path of the unzipped file. |
| options | [Options](#options)| No | Optional parameters for the unzip operation. | | options | [Options](#options) | No | Optional parameters for the unzip operation. |
**Return value** **Return value**
...@@ -106,61 +106,67 @@ import zlib from '@ohos.zlib' ...@@ -106,61 +106,67 @@ import zlib from '@ohos.zlib'
var inFile = "/xx/xxx.zip"; var inFile = "/xx/xxx.zip";
var outFile = "/xxx"; var outFile = "/xxx";
var options = {}; let options = {
options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION; level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
options.memLevel = zlib.MemLevel.MEM_LEVEL_DEFAULT; memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY; strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
};
zlib.unzipFile(inFile, outFile, options).then((data) => { zlib.unzipFile(inFile, outFile, options).then((data) => {
if (data == zlib.ErrorCode.ERROR_CODE_OK) { console.log("unzipFile result: " + data);
console.log("unzipFile OK");
} else {
console.log("unzipFile NG");
}
}).catch((err)=>{ }).catch((err)=>{
console.log("catch((err)=>" + err); console.log("catch((err)=>" + err);
}) })
``` ```
## options ## Options
| Name | Description | **System capability**: SystemCapability.BundleManager.Zlib
| --------------------------- | ------------------------------------------------------------ |
| level?: CompressLeve | See [zip.CompressLevel](#zipcompresslevel). | | Name | Type | Mandatory| Description |
| memLevel?: MemLevel | See [zip.MemLevel](#zipmemlevel) | | -------- | ---------------- | ---- | --------------------------------------------------------- |
| strategy?: CompressStrategy | See [zip.CompressStrategy](#zipcompressstrategy) | | level | CompressLeve | No | See [zip.CompressLevel](#zipcompresslevel). |
| memLevel | MemLevel | No | See [zip.MemLevel](#zipmemlevel). |
| strategy | CompressStrategy | No | See [zip.CompressStrategy](#zipcompressstrategy).|
## zip.MemLevel ## zip.MemLevel
| Name | Description | **System capability**: SystemCapability.BundleManager.Zlib
| ----------------- | -------------------------------- |
| MEM_LEVEL_MIN | Minimum memory used by the **zip** API during compression.| | Name | Value | Description |
| MEM_LEVEL_MAX | Maximum memory used by the **zip** API during compression.| | ----------------- | ---- | -------------------------------- |
| MEM_LEVEL_DEFAULT | Default memory used by the **zip** API during compression.| | MEM_LEVEL_MIN | 1 | Minimum memory used by the **zip** API during compression.|
| MEM_LEVEL_MIN | 9 | Maximum memory used by the **zip** API during compression.|
| MEM_LEVEL_DEFAULT | 8 | Default memory used by the **zip** API during compression.|
## zip.CompressLevel
## Zip.CompressLevel **System capability**: SystemCapability.BundleManager.Zlib
| Name | Description | | Name | Value | Description |
| --------------------------------------- | ----------------- | | ---------------------------------- | ---- | ----------------- |
| COMPRESS_LEVEL_NO_COMPRESSION : 0 | Compress level 0 that indicates uncompressed.| | COMPRESS_LEVEL_NO_COMPRESSION | 0 | Compress level 0 that indicates uncompressed.|
| COMPRESS_LEVEL_BEST_SPEED : 1 | Compression level 1 that gives the best speed. | | COMPRESS_LEVEL_BEST_SPEED | 1 | Compression level 1 that gives the best speed. |
| COMPRESS_LEVEL_BEST_COMPRESSION :9 | Compression level 9 that gives the best compression. | | COMPRESS_LEVEL_BEST_COMPRESSION | 9 | Compression level 9 that gives the best compression. |
| COMPRESS_LEVEL_DEFAULT_COMPRESSION : -1| Default compression level. | | COMPRESS_LEVEL_DEFAULT_COMPRESSION | -1 | Default compression level. |
## Zip.CompressStrategy ## zip.CompressStrategy
| Name | Description | **System capability**: SystemCapability.BundleManager.Zlib
| -------------------------------------- | ------------------------ |
| COMPRESS_STRATEGY_DEFAULT_STRATEGY : 0 | Default compression strategy. | | Name | Value | Description |
| COMPRESS_STRATEGY_FILTERED : 1 | Filtered compression strategy.| | ---------------------------------- | ---- | ------------------------ |
| COMPRESS_STRATEGY_HUFFMAN_ONLY : 2 | Huffman coding compression strategy. | | COMPRESS_STRATEGY_DEFAULT_STRATEGY | 0 | Default compression strategy. |
| COMPRESS_STRATEGY_RLE : 3 | RLE compression strategy. | | COMPRESS_STRATEGY_FILTERED | 1 | Filtered compression strategy.|
| COMPRESS_STRATEGY_FIXED : 4 | Fixed compression strategy. | | COMPRESS_STRATEGY_HUFFMAN_ONLY | 2 | Huffman coding compression strategy. |
| COMPRESS_STRATEGY_RLE | 3 | RLE compression strategy. |
| COMPRESS_STRATEGY_FIXED | 4 | Fixed compression strategy. |
## zip.ErrorCode ## zip.ErrorCode
| Name | Description | **System capability**: SystemCapability.BundleManager.Zlib
| -------------------- | ------------ |
| ERROR_CODE_OK: 0 | The API is successfully called.| | Name | Value | Description |
| ERROR_CODE_ERRNO:- 1 | Failed to call the API.| | ---------------- | ---- | ------------ |
| ERROR_CODE_OK | 0 | The API is successfully called.|
| ERROR_CODE_ERRNO | -1 | Failed to call the API.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册