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

!16364 [翻译完成】#I6LMDK (15869+15956+15849)

Merge pull request !16364 from Annie_wang/PR15808
......@@ -102,8 +102,13 @@ Creates an **X509Cert** instance. This API uses an asynchronous callback to retu
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | -------------------------- |
| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. |
| callback | AsyncCallback\<X509Cert> | Yes | Callback invoked to return the result. **X509Cer** instance created.|
| callback | AsyncCallback\<X509Cert> | Yes | Callback invoked to return the result. **X509Cert** instance created.|
**Error codes**
| ID| Error Message |
| -------- | ------------- |
| 19020001 | Memory error. |
**Example**
......@@ -115,7 +120,7 @@ let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
......@@ -144,7 +149,13 @@ Creates an **X509Cert** instance. This API uses a promise to return the result.
| Type | Description |
| ------- | ---------------- |
| Promise\<X509Cert> | **X509Cer** instance created.|
| Promise\<X509Cert> | **X509Cert** instance created.|
**Error codes**
| ID| Error Message |
| -------- | ------------- |
| 19020001 | Memory error. |
**Example**
......@@ -184,12 +195,16 @@ Verifies the certificate signature. This API uses an asynchronous callback to re
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
**Error codes**
| ID| Error Message |
| -------- | ------------------ |
| 19030001 | Crypto operation error. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Certificate binary data, which must be set based on the service.
let encodingData = null;
......@@ -236,6 +251,12 @@ Verifies the certificate signature. This API uses a promise to return the result
| -------------- | ----------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ------------------ |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -250,7 +271,7 @@ let encodingBlob = {
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
console.log("createX509Cert success");
// Generate a public key by AsyKeyGenerator or obtain the public key by using getPublicKey() of the X509Cert instance.
// The service can call getPublicKey() of the upper-level X509Cert object to obtain the public key.
let pubKey = null;
x509Cert.verify(pubKey).then(result => {
console.log("verify success");
......@@ -276,6 +297,13 @@ Obtains the serialized X.509 certificate data. This API uses an asynchronous cal
| -------- | --------------------------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized X.509 certificate data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
......@@ -319,6 +347,14 @@ Obtains the serialized X.509 certificate data. This API uses a promise to return
| --------------------------------------- | ---------------------- |
| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized X.509 certificate data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -357,6 +393,13 @@ Obtains the public key of this X.509 certificate. This API uses an asynchronous
| ------ | ---------------- |
| cryptoFramework.PubKey | Public key of the X509 certificate obtained. This object is used only for **verify()** of **X509Cert**.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -399,6 +442,15 @@ Checks the validity period of this X.509 certificate. This API uses an asynchron
| -------- | -------------- | ---- | ---------- |
| date | string | Yes | Date in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The date must end with **Z**, which indicates the UTC.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error.|
| 19030003 | The certificate has not taken effect. |
| 19030004 | The certificate has expired.|
**Example**
```js
......@@ -514,6 +566,14 @@ Obtains the X.509 certificate issuer.
| --------------------- | ---------------------- |
| [DataBlob](#datablob) | X.509 certificate issuer obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -550,6 +610,14 @@ Obtains the subject of this X.509 certificate.
| --------------------- | -------------------- |
| [DataBlob](#datablob) | Subject name obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -586,6 +654,14 @@ Obtains the start time of this X.509 certificate.
| ------ | ------------------------------------------------------------ |
| string | Start time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -622,6 +698,14 @@ Obtains the expiration time of this X.509 certificate.
| ------ | ------------------------------------------------------------ |
| string | Expiration time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -658,6 +742,14 @@ Obtains the signature data of this X.509 certificate.
| --------------------- | -------------------- |
| [DataBlob](#datablob) | Signature data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -694,6 +786,14 @@ Obtains the signing algorithm of this X.509 certificate.
| ------ | ------------------------ |
| string | X.509 certificate signing algorithm obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -730,6 +830,14 @@ Obtains the object identifier (OID) of the X.509 certificate signing algorithm.
| ------ | --------------------------------- |
| string | OID obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -766,6 +874,14 @@ Obtains the signing algorithm parameters of this X.509 certificate.
| --------------------- | ------------------------ |
| [DataBlob](#datablob) | X.509 certificate signing algorithm parameters obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -802,6 +918,13 @@ Obtains the key usage of this X.509 certificate.
| --------------------- | -------------------- |
| [DataBlob](#datablob) | Key usage of the X.509 certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -838,6 +961,14 @@ Obtains the usage of the extended key of this X.509 certificate.
| ----------------------- | ------------------------ |
| [DataArray](#dataarray) | Usage of the extended key obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -910,6 +1041,14 @@ Obtains the Subject Alternative Names (SANs) of this X.509 certificate.
| ----------------------- | ------------------------ |
| [DataArray](#dataarray) | SANs obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -946,6 +1085,14 @@ Obtains the Issuer Alternative Names (IANs) of this X.509 certificate.
| ----------------------- | -------------------------- |
| [DataArray](#dataarray) | IANs obtained.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error.|
**Example**
```js
......@@ -983,6 +1130,11 @@ Creates an **X509Crl** instance. This API uses an asynchronous callback to retur
| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized certificate revocation list (CRL) data. |
| callback | AsyncCallback\<X509Crl> | Yes | Callback invoked to return the result. Promise used to return the **X509Crl** instance created.|
**Error codes**
| ID| Error Message |
| -------- | ------------- |
| 19020001 | Memory error. |
**Example**
......@@ -1025,6 +1177,12 @@ Creates an **X509Crl** instance. This API uses a promise to return the result.
| ----------------- | -------------------- |
| Promise\<X509Crl> | Promise used to return the **X509Crl** instance created.|
**Error codes**
| ID| Error Message |
| -------- | ------------- |
| 19020001 | Memory error. |
**Example**
```js
......@@ -1146,6 +1304,13 @@ Obtains the serialized X.509 CRL data. This API uses an asynchronous callback to
| -------- | ---------------------------- | ---- | ------------------------------------------ |
| callback | AsyncCallback\<EncodingBlob> | Yes | Callback invoked to return the serialized X.509 CRL data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
......@@ -1189,6 +1354,14 @@ Obtains the serialized X.509 CRL data. This API uses a promise to return the res
| ---------------------- | -------------------------------- |
| Promise\<EncodingBlob> | Promise used to return the serialized X.509 CRL data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1217,7 +1390,7 @@ cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void
Verifies the signature of the X.509 CRL. This API uses an asynchronous callback to return the result.
Verifies the signature of the X.509 CRL. This API uses an asynchronous callback to return the result. The RSA algorithm is supported.
**System capability**: SystemCapability.Security.Cert
......@@ -1225,9 +1398,14 @@ Verifies the signature of the X.509 CRL. This API uses an asynchronous callback
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19030001 | Crypto operation error. |
**Example**
......@@ -1264,7 +1442,7 @@ cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
verify(key : cryptoFramework.PubKey) : Promise\<void>
Verifies the signature of the X.509 CRL. This API uses a promise to return the result.
Verifies the signature of the X.509 CRL. This API uses a promise to return the result. The RSA algorithm is supported.
**System capability**: SystemCapability.Security.Cert
......@@ -1280,6 +1458,12 @@ Verifies the signature of the X.509 CRL. This API uses a promise to return the r
| ---- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1357,6 +1541,14 @@ Obtains the issuer of the X.509 CRL.
| --------------------- | ------------------------------ |
| [DataBlob](#datablob) | Issuer of the X.509 CRL obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1393,6 +1585,14 @@ Obtains the date when the X.509 CRL was last updated.
| ------ | ------------------------------------ |
| string | Last update date of the X.509 CRL.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1429,6 +1629,14 @@ Obtains the date when the CRL will be updated the next time.
| ------ | ------------------------------------ |
| string | Next update date obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1471,6 +1679,13 @@ Obtains the revoked X.509 certificate based on the specified serial number of th
| ---------------------- | --------------------- |
| X509CrlEntry | Promise used to return the revoked X.509 certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1519,6 +1734,13 @@ Obtains the revoked X.509 certificate based on the specified certificate. This A
| ------------ | -------------------- |
| X509CrlEntry | Promise used to return the revoked X.509 certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1561,6 +1783,12 @@ Obtains all the revoked X.509 certificates. This API uses an asynchronous callba
| -------- | ----------------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback<Array\<X509CrlEntry>> | Yes | Callback invoked to return the result. Promise used to return a list of revoked X.509 certificates.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error. |
**Example**
......@@ -1604,6 +1832,13 @@ Obtains all the revoked X.509 certificates. This API uses a promise to return th
| ----------------------------- | ---------------------- |
| Promise<Array\<X509CrlEntry>> | Promise used to return a list of revoked X.509 certificates.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1642,6 +1877,14 @@ Obtains the DER-encoded CRL information, the **tbsCertList** from this CRL. This
| --------------------- | ------------------------------- |
| [DataBlob](#datablob) | Promise used to return the **tbsCertList** information obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1682,6 +1925,14 @@ Obtains the signature data of the X.509 CRL.
| --------------------- | ------------------------------ |
| [DataBlob](#datablob) | Signature data of the X.509 CRL obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1718,6 +1969,14 @@ Obtains the signing algorithm of the X.509 CRL.
| ------ | -------------------------------- |
| string | Signing algorithm obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1754,6 +2013,14 @@ Obtains the OID of the X.509 CRL signing algorithm. OIDs are allocated by the In
| ------ | --------------------------------------------- |
| string | OID of the X.509 CRL signing algorithm obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1790,6 +2057,14 @@ Obtains the parameters of the X.509 CRL signing algorithm.
| --------------------- | ---------------------------------- |
| [DataBlob](#datablob) | Algorithm parameters obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1832,6 +2107,14 @@ Creates a **CertChainValidator** object.
| ------------------ | -------------------- |
| CertChainValidator | **CertChainValidator** object created.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -1847,7 +2130,7 @@ Provides APIs for certificate chain validator operations.
### Attributes
**System capability**: SystemCapability.Security.CryptoFramework
**System capability**: SystemCapability.Security.Cert
| Name | Type | Readable| Writable| Description |
| ------- | ------ | ---- | ---- | -------------------------- |
......@@ -1870,6 +2153,19 @@ The certificate chain validator does not verify the certificate validity period
| certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data. |
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
| 19030002 | The certificate signature verification failed. |
| 19030003 | The certificate has not taken effect. |
| 19030004 | The certificate has expired. |
| 19030005 | Failed to obtain the certificate issuer. |
| 19030006 | The key cannot be used for signing a certificate. |
| 19030007 | The key cannot be used for digital signature. |
**Example**
......@@ -1917,6 +2213,20 @@ The certificate chain validator does not verify the certificate validity period
| -------------- | ----------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ------------------------------------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
| 19030002 | The certificate signature verification failed. |
| 19030003 | The certificate has not taken effect. |
| 19030004 | The certificate has expired. |
| 19030005 | Failed to obtain the certificate issuer. |
| 19030006 | The key cannot be used for signing a certificate. |
| 19030007 | The key cannot be used for digital signature. |
**Example**
```js
......@@ -1981,6 +2291,13 @@ Obtains the serialized data of this revoked certificate. This API uses an asynch
| -------- | --------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized data of the revoked certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
......@@ -2012,6 +2329,14 @@ Obtains the serialized data of this revoked certificate. This API uses a promise
| --------------------------------------- | -------------------------- |
| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized data of the revoked certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......@@ -2061,9 +2386,16 @@ Obtains the issuer of this revoked certificate. This API uses an asynchronous ca
**Return value**
| Type | Description |
| --------------------- | ---------------------- - |
| --------------------- | ----------------------- |
| [DataBlob](#datablob) | Promise used to return the issuer of the revoked certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | -------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
**Example**
```js
......@@ -2092,6 +2424,14 @@ Obtains the date when the certificate was revoked. This API uses an asynchronous
| ------ | ------------------ |
| string | Promise used to return the certificate revocation date obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
```js
......
......@@ -28,7 +28,7 @@ Provides the **KVManager** instance configuration, including the bundle name of
| Name | Type | Mandatory| Description |
| ---------- | --------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes |Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes |Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| bundleName | string | Yes | Bundle name. |
## Constants
......@@ -272,7 +272,6 @@ Stage model:
```js
import UIAbility from '@ohos.app.ability.UIAbility'
let kvManager;
export default class EntryAbility extends UIAbility {
onCreate() {
......@@ -358,7 +357,7 @@ try {
console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`);
return;
}
console.log("Obtained the KVStore successfully.");
console.log("Succeeded in getting KVStore");
kvStore = store;
});
} catch (e) {
......@@ -411,7 +410,7 @@ try {
securityLevel: distributedKVStore.SecurityLevel.S2,
};
kvManager.getKVStore('storeId', options).then((store) => {
console.log("Obtained the KVStore successfully.");
console.log("Succeeded in getting KVStore");
kvStore = store;
}).catch((err) => {
console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`);
......@@ -453,14 +452,14 @@ const options = {
}
try {
kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('Obtained the KVStore successfully.');
console.log('Succeeded in getting KVStore');
kvStore = store;
kvManager.closeKVStore('appId', 'storeId', function (err, data) {
if (err != undefined) {
console.error(`Fail to close KVStore.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the KVStore successfully.');
console.log('Succeeded in closing KVStore');
});
});
} catch (e) {
......@@ -505,10 +504,10 @@ const options = {
}
try {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('Obtained the KVStore successfully.');
console.log('Succeeded in getting KVStore');
kvStore = store;
kvManager.closeKVStore('appId', 'storeId').then(() => {
console.log('Closed the KVStore successfully.');
console.log('Succeeded in closing KVStore');
}).catch((err) => {
console.error(`Fail to close KVStore.code is ${err.code},message is ${err.message}`);
});
......@@ -564,14 +563,14 @@ try {
console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the KVStore successfully.');
console.log('Succeeded in getting KVStore');
kvStore = store;
kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
if (err != undefined) {
console.error(`Fail to delete KVStore.code is ${err.code},message is ${err.message}`);
return;
}
console.log(`Deleted the KVStore successfully.`);
console.log(`Succeeded in deleting KVStore`);
});
});
} catch (e) {
......@@ -624,10 +623,10 @@ const options = {
}
try {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('Obtained the KVStore successfully.');
console.log('Succeeded in getting KVStore');
kvStore = store;
kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('Deleted the KVStore successfully.');
console.log('Succeeded in deleting KVStore');
}).catch((err) => {
console.error(`Fail to delete KVStore.code is ${err.code},message is ${err.message}`);
});
......@@ -664,7 +663,7 @@ try {
console.error(`Fail to get AllKVStoreId.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained all KV store IDs successfully.');
console.log('Succeeded in getting AllKVStoreId');
console.log(`GetAllKVStoreId size = ${data.length}`);
});
} catch (e) {
......@@ -699,7 +698,7 @@ let kvManager;
try {
console.log('GetAllKVStoreId');
kvManager.getAllKVStoreId('appId').then((data) => {
console.log('Obtained all KV store IDs successfully.');
console.log('Succeeded in getting AllKVStoreId');
console.log(`GetAllKVStoreId size = ${data.length}`);
}).catch((err) => {
console.error(`Fail to get AllKVStoreId.code is ${err.code},message is ${err.message}`);
......@@ -829,7 +828,7 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully.');
console.log('getResultSet succeeded.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet failed: ' + err);
......@@ -1000,7 +999,7 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
......@@ -1039,7 +1038,7 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
......@@ -1242,7 +1241,7 @@ Resets the **Query** object.
| Type | Description |
| -------------- | --------------------- |
| [Query](query) | **Query** object reset.|
| [Query](#query) | **Query** object reset.|
**Example**
......@@ -1278,7 +1277,7 @@ Creates a **Query** object to match the specified field whose value is equal to
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1312,7 +1311,7 @@ Creates a **Query** object to match the specified field whose value is not equal
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1345,7 +1344,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1380,7 +1379,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1415,7 +1414,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1450,7 +1449,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1483,7 +1482,7 @@ Creates a **Query** object to match the specified field whose value is **null**.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1517,7 +1516,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1551,7 +1550,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1585,7 +1584,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1619,7 +1618,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1653,7 +1652,7 @@ Creates a **Query** object to match the specified field whose value is similar t
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1687,7 +1686,7 @@ Creates a **Query** object to match the specified field whose value is not simil
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1714,7 +1713,7 @@ Creates a **Query** object with the AND condition.
| Type | Description |
| -------------- | -------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1743,7 +1742,7 @@ Creates a **Query** object with the OR condition.
| Type | Description |
| -------------- | -------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1778,7 +1777,7 @@ Creates a **Query** object to sort the query results in ascending order.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1812,7 +1811,7 @@ Creates a **Query** object to sort the query results in descending order.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1847,7 +1846,7 @@ Creates a **Query** object to specify the number of results and where to start.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1883,7 +1882,7 @@ Creates a **Query** object to match the specified field whose value is not **nul
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1910,7 +1909,7 @@ Creates a **Query** object for a query condition group with a left parenthesis.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1939,7 +1938,7 @@ Creates a **Query** object for a query condition group with a right parenthesis.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -1974,7 +1973,7 @@ Creates a **Query** object with a specified key prefix.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -2008,7 +2007,7 @@ Creates a **Query** object with an index preferentially used for query.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -2042,7 +2041,7 @@ Creates a **Query** object with the device ID as the key prefix.
| Type | Description |
| -------------- | --------------- |
| [Query](query) | **Query** object created.|
| [Query](#query) | **Query** object created.|
**Example**
......@@ -2125,7 +2124,7 @@ try {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log("Put data successfully.");
console.log("Succeeded in putting");
});
} catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`);
......@@ -2170,7 +2169,7 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log(`Put data successfully. data=${data}`);
console.log(`Succeeded in putting.data=${data}`);
}).catch((err) => {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
});
......@@ -2226,12 +2225,12 @@ try {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -2289,9 +2288,9 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (entries) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key').then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`PutBatch ${entries}`);
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
......@@ -2349,7 +2348,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
})
} catch (e) {
console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`);
......@@ -2402,7 +2401,7 @@ try {
v8Arr.push(vb2);
v8Arr.push(vb3);
kvStore.putBatch(v8Arr).then(async (data) => {
console.log(`Batch put data successfully.`);
console.log(`Succeeded in putting patch`);
}).catch((err) => {
console.error(`putBatch fail.code is ${err.code},message is ${err.message}`);
});
......@@ -2447,13 +2446,13 @@ try {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Put data successfully.');
console.log('Succeeded in putting');
kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to delete.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Deleted data successfully.');
console.log('Succeeded in deleting');
});
});
} catch (e) {
......@@ -2498,9 +2497,9 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log(`Put data successfully: ${data}`);
console.log(`Succeeded in putting: ${data}`);
kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('Deleted data successfully.');
console.log('Succeeded in deleting');
}).catch((err) => {
console.error(`Fail to delete.code is ${err.code},message is ${err.message}`);
});
......@@ -2547,7 +2546,7 @@ try {
let predicates = new dataSharePredicates.DataSharePredicates();
kvStore.delete(predicates, function (err, data) {
if (err == undefined) {
console.log('Deleted data successfully.');
console.log('Succeeded in deleting');
} else {
console.error(`Fail to delete.code is ${err.code},message is ${err.message}`);
}
......@@ -2599,9 +2598,9 @@ try {
let arr = ["name"];
predicates.inKeys(arr);
kvStore.put("name", "bob").then((data) => {
console.log(`Put data successfully: ${data}`);
console.log(`Succeeded in putting: ${data}`);
kvStore.delete(predicates).then((data) => {
console.log('Deleted data successfully.');
console.log('Succeeded in deleting');
}).catch((err) => {
console.error(`Fail to delete.code is ${err.code},message is ${err.message}`);
});
......@@ -2662,13 +2661,13 @@ try {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.deleteBatch(keys, async function (err, data) {
if (err != undefined) {
console.error(`Fail to delete Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch deleted data successfully.');
console.log('Succeeded in deleting Batch');
});
});
} catch (e) {
......@@ -2726,9 +2725,9 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (data) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.deleteBatch(keys).then((err) => {
console.log('Batch deleted data successfully.');
console.log('Succeeded in deleting Batch');
}).catch((err) => {
console.error(`Fail to delete Batch.code is ${err.code},message is ${err.message}`);
});
......@@ -2771,15 +2770,15 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err, data) {
console.log('Put data successfully.');
console.log('Succeeded in putting data');
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid, async function (err, data) {
if (err == undefined) {
console.log('Removed device data successfully.');
console.log('succeeded in removing device data');
} else {
console.error(`Fail to remove device data.code is ${err.code},message is ${err.message} `);
kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err, data) {
console.log('Obtained data successfully.');
console.log('Succeeded in getting data');
});
}
});
......@@ -2825,18 +2824,18 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('Put data successfully.');
console.log('Succeeded in putting data');
}).catch((err) => {
console.error(`Fail to put data.code is ${err.code},message is ${err.message} `);
});
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => {
console.log('Removed device data successfully.');
console.log('succeeded in removing device data');
}).catch((err) => {
console.error(`Fail to remove device data.code is ${err.code},message is ${err.message} `);
});
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('Obtained data successfully.');
console.log('Succeeded in getting data');
}).catch((err) => {
console.error(`Fail to get data.code is ${err.code},message is ${err.message} `);
});
......@@ -2882,13 +2881,13 @@ try {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log("Put data successfully.");
console.log("Succeeded in putting");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
return;
}
console.log(`Obtained data successfully. data=${data}`);
console.log(`Succeeded in getting data.data=${data}`);
});
});
} catch (e) {
......@@ -2934,9 +2933,9 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log(`Put data successfully. data=${data}`);
console.log(`Succeeded in putting data.data=${data}`);
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log(`Obtained data successfully. data=${data}`);
console.log(`Succeeded in getting data.data=${data}`);
}).catch((err) => {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
});
......@@ -2995,13 +2994,13 @@ try {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -3059,9 +3058,9 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (entries) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key').then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`PutBatch ${entries}`);
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
......@@ -3086,7 +3085,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses an
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ----------------------------------------------- |
| query | [Query](query) | Yes | Key prefix to match. |
| query | [Query](#query) | Yes | Key prefix to match. |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes | Callback invoked to return the KV pairs obtained.|
**Error codes**
......@@ -3118,7 +3117,7 @@ try {
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries, async function (err, data) {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query, function (err, entries) {
......@@ -3126,7 +3125,7 @@ try {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -3148,7 +3147,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses a
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -3185,18 +3184,18 @@ try {
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query).then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`)
});
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
} catch (e) {
console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`);
}
......@@ -3249,20 +3248,20 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
kvStore.getResultSet('batch_test_string_key', async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
})
});
});
......@@ -3319,18 +3318,18 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -3386,7 +3385,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query, async function (err, result) {
......@@ -3394,7 +3393,7 @@ try {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
});
});
} catch (e) {
......@@ -3414,7 +3413,7 @@ Obtains a **KVStoreResultSet** object that matches the specified **Query** objec
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -3450,14 +3449,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
......@@ -3508,14 +3507,14 @@ try {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
})
});
} catch (e) {
......@@ -3565,13 +3564,13 @@ try {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.prefixKey("batch_test_string_key");
kvStore.getResultSet(predicates).then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -3603,7 +3602,7 @@ try {
let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
} else {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
}
......@@ -3640,7 +3639,7 @@ let kvStore;
try {
let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -3661,7 +3660,7 @@ Obtains the number of results that matches the specified **Query** object. This
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------- |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of results obtained.|
**Error codes**
......@@ -3691,7 +3690,7 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query, async function (err, resultSize) {
......@@ -3699,7 +3698,7 @@ try {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set size successfully');
console.log('Succeeded in getting result set size');
});
});
} catch (e) {
......@@ -3719,7 +3718,7 @@ Obtains the number of results that matches the specified **Query** object. This
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -3754,14 +3753,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('Obtained the result set size successfully');
console.log('Succeeded in getting result set size');
}).catch((err) => {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
});
......@@ -3803,7 +3802,7 @@ try {
if (err) {
console.error(`Fail to backup.code is ${err.code},message is ${err.message} `);
} else {
console.info(`Backed up data successfully. data=${data}`);
console.info(`Succeeded in backupping data.data=${data}`);
}
});
} catch (e) {
......@@ -3846,7 +3845,7 @@ let kvStore;
let file = "BK001";
try {
kvStore.backup(file).then((data) => {
console.info(`Backed up data successfully. data=${data}`);
console.info(`Succeeded in backupping data.data=${data}`);
}).catch((err) => {
console.error(`Fail to backup.code is ${err.code},message is ${err.message}`);
});
......@@ -3888,7 +3887,7 @@ try {
if (err) {
console.error(`Fail to restore.code is ${err.code},message is ${err.message}`);
} else {
console.info(`Restored data successfully. data=${data}`);
console.info(`Succeeded in restoring data.data=${data}`);
}
});
} catch (e) {
......@@ -3931,7 +3930,7 @@ let kvStore;
let file = "BK001";
try {
kvStore.restore(file).then((data) => {
console.info(`Restored data successfully. data=${data}`);
console.info(`Succeeded in restoring data.data=${data}`);
}).catch((err) => {
console.error(`Fail to restore.code is ${err.code},message is ${err.message}`);
});
......@@ -3965,7 +3964,7 @@ try {
if (err) {
console.error(`Fail to delete Backup.code is ${err.code},message is ${err.message}`);
} else {
console.info(`Deleted the backup file successfully. data=${data}`);
console.info(`Succeed in deleting Backup.data=${data}`);
}
});
} catch (e) {
......@@ -4000,7 +3999,7 @@ let kvStore;
let files = ["BK001", "BK002"];
try {
kvStore.deleteBackup(files).then((data) => {
console.info(`Deleted the backup file successfully. data=${data}`);
console.info(`Succeed in deleting Backup.data=${data}`);
}).catch((err) => {
console.error(`Fail to delete Backup.code is ${err.code},message is ${err.message}`);
})
......@@ -4061,7 +4060,7 @@ try {
console.error(`Fail to start Transaction.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Started the transaction successfully.');
console.log('Succeeded in starting Transaction');
let entries = putBatchString(10, 'batch_test_string_key');
console.log(`entries: ${entries}`);
kvStore.putBatch(entries, async function (err, data) {
......@@ -4069,7 +4068,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
});
});
} catch (e) {
......@@ -4110,7 +4109,7 @@ try {
count++;
});
kvStore.startTransaction().then(async (err) => {
console.log('Started the transaction successfully.');
console.log('Succeeded in starting Transaction');
}).catch((err) => {
console.error(`Fail to start Transaction.code is ${err.code},message is ${err.message}`);
});
......@@ -4148,7 +4147,7 @@ let kvStore;
try {
kvStore.commit(function (err, data) {
if (err == undefined) {
console.log('Committed the transaction successfully.');
console.log('Succeeded in committing');
} else {
console.error(`Fail to commit.code is ${err.code},message is ${err.message}`);
}
......@@ -4186,7 +4185,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
let kvStore;
try {
kvStore.commit().then(async (err) => {
console.log('Committed the transaction successfully.');
console.log('Succeeded in committing');
}).catch((err) => {
console.error(`Fail to commit.code is ${err.code},message is ${err.message}`);
});
......@@ -4224,7 +4223,7 @@ let kvStore;
try {
kvStore.rollback(function (err,data) {
if (err == undefined) {
console.log('Rolled back the transaction successfully');
console.log('Succeeded in rolling back');
} else {
console.error(`Fail to rollback.code is ${err.code},message is ${err.message}`);
}
......@@ -4262,7 +4261,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
let kvStore;
try {
kvStore.rollback().then(async (err) => {
console.log('Rolled back the transaction successfully');
console.log('Succeeded in rolling back');
}).catch((err) => {
console.error(`Fail to rollback.code is ${err.code},message is ${err.message}`);
});
......@@ -4293,7 +4292,7 @@ let kvStore;
try {
kvStore.enableSync(true, function (err, data) {
if (err == undefined) {
console.log('Enabled sync successfully.');
console.log('Succeeded in enabling sync');
} else {
console.error(`Fail to enable sync.code is ${err.code},message is ${err.message}`);
}
......@@ -4329,7 +4328,7 @@ Sets data synchronization, which can be enabled or disabled. This API uses a pro
let kvStore;
try {
kvStore.enableSync(true).then((err) => {
console.log('Enabled sync successfully.');
console.log('Succeeded in enabling sync');
}).catch((err) => {
console.error(`Fail to enable sync.code is ${err.code},message is ${err.message}`);
});
......@@ -4366,7 +4365,7 @@ try {
console.error(`Fail to set syncRange.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Set syncRange successfully.');
console.log('Succeeded in setting syncRange');
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`);
......@@ -4402,7 +4401,7 @@ try {
const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => {
console.log('Set syncRange successfully.');
console.log('Succeeded in setting syncRange');
}).catch((err) => {
console.error(`Fail to set syncRange.code is ${err.code},message is ${err.message}`);
});
......@@ -4437,7 +4436,7 @@ try {
console.error(`Fail to set syncParam.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Set syncParam successfully');
console.log('Succeeded in setting syncParam');
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`);
......@@ -4471,7 +4470,7 @@ let kvStore;
try {
const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => {
console.log('Set syncParam successfully');
console.log('Succeeded in setting syncParam');
}).catch((err) => {
console.error(`Fail to set syncParam.code is ${err.code},message is ${err.message}`);
});
......@@ -4522,7 +4521,7 @@ try {
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Put data successfully.');
console.log('Succeeded in putting data');
const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode, 1000);
......@@ -4548,7 +4547,7 @@ Synchronizes the KV store manually. This API returns the result synchronously. F
| --------- | --------------------- | ---- | ---------------------------------------------- |
| deviceIds | string[] | Yes | List of IDs of the devices in the same networking environment to be synchronized.|
| mode | [SyncMode](#syncmode) | Yes | Synchronization mode. |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| delayMs | number | No | Allowed synchronization delay time, in ms. |
**Error codes**
......@@ -4575,7 +4574,7 @@ try {
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Put data successfully.');
console.log('Succeeded in putting data');
const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
const query = new distributedKVStore.Query();
......@@ -4652,7 +4651,7 @@ try {
console.log(`syncComplete ${data}`);
});
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('Put data successfully.');
console.log('succeeded in putting');
}).catch((err) => {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
});
......@@ -4793,7 +4792,7 @@ try {
console.error(`Fail to get SecurityLevel.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained securityLevel successfully');
console.log('Succeeded in getting securityLevel');
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`);
......@@ -4828,7 +4827,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
let kvStore;
try {
kvStore.getSecurityLevel().then((data) => {
console.log('Obtained securityLevel successfully');
console.log('Succeeded in getting securityLevel');
}).catch((err) => {
console.error(`Fail to get SecurityLevel.code is ${err.code},message is ${err.message}`);
});
......@@ -4884,13 +4883,13 @@ try {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log("Put data successfully.");
console.log("Succeeded in putting");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
return;
}
console.log(`Obtained data successfully. data=${data}`);
console.log(`Succeeded in getting data.data=${data}`);
});
});
} catch (e) {
......@@ -4936,9 +4935,9 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log(`Put data successfully. data=${data}`);
console.log(`Succeeded in putting data.data=${data}`);
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log(`Obtained data successfully. data=${data}`);
console.log(`Succeeded in getting data.data=${data}`);
}).catch((err) => {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
});
......@@ -4988,13 +4987,13 @@ try {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Put data successfully.');
console.log('Succeeded in putting');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained data successfully');
console.log('Succeeded in getting');
});
})
} catch (e) {
......@@ -5041,9 +5040,9 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => {
console.log('Put data successfully.');
console.log('Succeeded in putting');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('Obtained data successfully');
console.log('Succeeded in getting');
}).catch((err) => {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
});
......@@ -5102,13 +5101,13 @@ try {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -5166,9 +5165,9 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (entries) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key').then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`PutBatch ${entries}`);
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
......@@ -5229,13 +5228,13 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -5294,9 +5293,9 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
console.log(`entries[0].value: ${entries[0].value}`);
......@@ -5324,7 +5323,7 @@ Obtains all KV pairs that match the specified **Query** object for this device.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ----------------------------------------------------- |
| query | [Query](query) | Yes | Key prefix to match. |
| query | [Query](#query) | Yes | Key prefix to match. |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes | Callback invoked to return the KV pairs obtained.|
**Error codes**
......@@ -5356,7 +5355,7 @@ try {
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries, async function (err, data) {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query, function (err, entries) {
......@@ -5364,7 +5363,7 @@ try {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
......@@ -5386,7 +5385,7 @@ Obtains all KV pairs that match the specified **Query** object for this device.
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -5423,18 +5422,18 @@ try {
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query).then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`)
});
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting Entries');
} catch (e) {
console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`);
}
......@@ -5453,7 +5452,7 @@ Obtains the KV pairs that match the specified device ID and **Query** object. Th
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------- |
| deviceId | string | Yes | ID of the target device. |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes | Callback invoked to return the KV pairs obtained.|
**Error codes**
......@@ -5489,7 +5488,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
......@@ -5498,12 +5497,12 @@ try {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
})
});
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
}
......@@ -5522,7 +5521,7 @@ Obtains the KV pairs that match the specified device ID and **Query** object. Th
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | -------------------- |
| deviceId | string | Yes | ID of the target device.|
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
**Return value**
......@@ -5559,19 +5558,19 @@ try {
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
kvStore.getEntries('localDeviceId', query).then((entries) => {
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
}).catch((err) => {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
console.log('Obtained the entries successfully.');
console.log('Succeeded in getting entries');
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
}
......@@ -5624,20 +5623,20 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
kvStore.getResultSet('batch_test_string_key', async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
})
});
});
......@@ -5694,18 +5693,18 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -5750,14 +5749,14 @@ try {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully.');
console.log('Succeeded in closing resultSet');
})
});
} catch (e) {
......@@ -5802,13 +5801,13 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully.');
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
......@@ -5830,7 +5829,7 @@ Obtains a **KVStoreResultSet** object that matches the specified device ID and *
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs. |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Yes | Callback invoked to return the **KVStoreResultSet** object obtained.|
**Error codes**
......@@ -5865,7 +5864,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query, async function (err, result) {
......@@ -5873,14 +5872,14 @@ try {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully.');
console.log('Succeeded in closing resultSet');
})
});
});
......@@ -5902,7 +5901,7 @@ Obtains a **KVStoreResultSet** object that matches the specified device ID and *
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs.|
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
**Return value**
......@@ -5938,14 +5937,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
......@@ -5953,7 +5952,7 @@ try {
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully.');
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
......@@ -5975,7 +5974,7 @@ Obtains a **KVStoreResultSet** object that matches the specified **Query** objec
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -6011,14 +6010,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
......@@ -6041,7 +6040,7 @@ Obtains a **KVStoreResultSet** object that matches the specified device ID and *
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs.|
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
**Return value**
......@@ -6077,14 +6076,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('Obtained the result set successfully.');
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
......@@ -6092,7 +6091,7 @@ try {
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully.');
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
......@@ -6143,14 +6142,14 @@ try {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
})
});
} catch (e) {
......@@ -6200,13 +6199,13 @@ try {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.prefixKey("batch_test_string_key");
kvStore.getResultSet(predicates).then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -6257,14 +6256,14 @@ try {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
})
});
} catch (e) {
......@@ -6314,13 +6313,13 @@ try {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.prefixKey("batch_test_string_key");
kvStore.getResultSet('localDeviceId', predicates).then((result) => {
console.log('Obtained the result set successfully');
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Closed the result set successfully');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
......@@ -6341,7 +6340,7 @@ Obtains the number of results that match the specified **Query** object for this
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------- |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of results that match the specified **Query** object.|
**Error codes**
......@@ -6371,7 +6370,7 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query, async function (err, resultSize) {
......@@ -6379,7 +6378,7 @@ try {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained the result set size successfully');
console.log('Succeeded in getting result set size');
});
});
} catch (e) {
......@@ -6399,7 +6398,7 @@ Obtains the number of results that match the specified **Query** object for this
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | Yes | **Query** object to match.|
| query | [Query](#query) | Yes | **Query** object to match.|
**Return value**
......@@ -6434,14 +6433,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('Obtained the result set size successfully');
console.log('Succeeded in getting result set size');
}).catch((err) => {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
});
......@@ -6463,7 +6462,7 @@ Obtains the number of results that matches the specified device ID and **Query**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | --------------------------------------------------- |
| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs. |
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of results obtained.|
**Error codes**
......@@ -6497,7 +6496,7 @@ try {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
......@@ -6505,7 +6504,7 @@ try {
console.error(`Fail to get resultSize.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Obtained resultSize successfully');
console.log('Succeeded in getting resultSize');
;
});
});
......@@ -6527,7 +6526,7 @@ Obtains the number of results that matches the specified device ID and **Query**
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs.|
| query | [Query](query) | Yes | **Query** object to match. |
| query | [Query](#query) | Yes | **Query** object to match. |
**Return value**
......@@ -6562,14 +6561,14 @@ try {
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Batch put data successfully.');
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
var query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('Obtained resultSize successfully');
console.log('Succeeded in getting resultSize');
;
}).catch((err) => {
console.error(`Fail to get resultSize.code is ${err.code},message is ${err.message}`);
......
......@@ -6,6 +6,7 @@ The **fileAccess** module is a framework for accessing and operating user files
>
>- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs provided by this module are system APIs and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **Files**.
>- The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
......@@ -25,9 +26,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
**Example**
......@@ -55,9 +56,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
**Example**
......@@ -89,16 +90,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
......@@ -136,15 +137,15 @@ Synchronously creates a **Helper** object to connect to all file management serv
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
......@@ -175,9 +176,9 @@ Obtains information about the device root nodes of the file management service t
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -220,9 +221,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -263,16 +264,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -314,15 +315,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -364,15 +365,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (direc
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -414,16 +415,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -465,10 +466,10 @@ Creates a file in a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
**Return value**
......@@ -510,11 +511,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
**Example**
......@@ -550,10 +551,10 @@ Creates a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
**Return value**
......@@ -595,11 +596,11 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the directory created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the directory created.|
**Example**
......@@ -635,10 +636,10 @@ Opens a file. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
**Return value**
......@@ -673,11 +674,11 @@ Opens a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
**Example**
......@@ -712,9 +713,9 @@ Deletes a file or directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
**Return value**
......@@ -751,10 +752,10 @@ Deletes a file or directory. This API uses an asynchronous callback to return th
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -781,7 +782,7 @@ Deletes a file or directory. This API uses an asynchronous callback to return th
move(sourceFile: string, destFile: string) : Promise&lt;string&gt;
Moves a file or directory. This API uses a promise to return the result.
Moves a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -789,22 +790,22 @@ Moves a file or directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
**Return value**
| Type| Description|
| ----- | ------ |
| Promise&lt;string&gt; | Promise used to return the URI of the file or directory in the destination directory.|
| Promise&lt;string&gt; | Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -821,7 +822,7 @@ Moves a file or directory. This API uses a promise to return the result.
move(sourceFile: string, destFile: string, callback: AsyncCallback&lt;string&gt;) : void;
Moves a file or directory. This API uses an asynchronous callback to return the result.
Moves a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -829,17 +830,17 @@ Moves a file or directory. This API uses an asynchronous callback to return the
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or directory in the destination directory.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -861,7 +862,7 @@ Moves a file or directory. This API uses an asynchronous callback to return the
rename(uri: string, displayName: string) : Promise&lt;string&gt;
Renames a file or directory. This API uses a promise to return the result.
Renames a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -869,16 +870,16 @@ Renames a file or directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or directory.|
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -900,7 +901,7 @@ Renames a file or directory. This API uses a promise to return the result.
rename(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
Renames a file or directory. This API uses an asynchronous callback to return the result.
Renames a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -908,11 +909,11 @@ Renames a file or directory. This API uses an asynchronous callback to return t
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or directory.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -939,7 +940,7 @@ Renames a file or directory. This API uses an asynchronous callback to return t
access(sourceFileUri: string) : Promise&lt;boolean&gt;
Checks whether a file or directory exists. This API uses a promise to return the result.
Checks whether a file or directory exists. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -947,9 +948,9 @@ Checks whether a file or directory exists. This API uses a promise to return th
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
**Return value**
......@@ -980,7 +981,7 @@ Checks whether a file or directory exists. This API uses a promise to return th
access(sourceFileUri: string, callback: AsyncCallback&lt;boolean&gt;) : void;
Checks whether a file or directory exists. This API uses an asynchronous callback to return the result.
Checks whether a file or directory exists. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -988,10 +989,10 @@ Checks whether a file or directory exists. This API uses an asynchronous callba
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -1031,13 +1032,13 @@ Obtains the next-level device root directory. **RootIterator** is an iterator ob
| Type| Description|
| --- | -- |
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.|
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.|
## FileIterator.next
next( ) : { value: FileInfo, done: boolean }
Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory.
Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1047,7 +1048,7 @@ Obtains the information about the next-level file or directory. **FileIterator*
| Type| Description|
| --- | -- |
| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.|
| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.|
## RootInfo
......@@ -1068,7 +1069,7 @@ Represents the root attribute information and interface capabilities of a device
## FileInfo
Represents the file or directory attribute information and interface capabilities.
Represents the file or directory attribute information and interface capabilities.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1078,12 +1079,12 @@ Represents the file or directory attribute information and interface capabiliti
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of a file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| MIME type of the file or directory.|
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of a file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| MIME type of the file or directory.|
## OPENFLAGS
......
# @system.cipher (Cipher Algorithm)
# @system.cipher (Cipher Algorithm)
> **NOTE**
>
> The initial APIs of this module are supported since API version 3. 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 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs provided by this module are deprecated since API version 9. You are advised to use [cryptoFramework-Cipher](js-apis-cryptoFramework.md#Cipher).
## Modules to Import
......@@ -18,9 +18,10 @@ Defines the response to the cipher interface called.
**System capability**: SystemCapability.Security.Cipher
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------ |
| text | string | Yes | Response content.|
| Name| Type | Readable| Writable|Description |
| ------ | ------ | ---- | ---- | ------------ |
| text | string | Yes | No | Response content.|
## CipherRsaOptions
......@@ -74,39 +75,39 @@ Encrypts or decrypts data using RSA.
**Example**
```js
export default {
rsa() {
cipher.rsa({
// Encrypt data.
action: 'encrypt',
// Text to be encrypted.
text: 'hello',
// Base64-encoded public key used for encryption.
key:
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCx414QSP3RsYWYzf9mkBMiBAXo\n' +
'6S7Lpva1fKlcuVxjoFC1iMnzD4mC0uiL4k5MNi43J64c7dbqi3qAJjdAtuwQ6NZJ\n' +
export default {
rsa() {
cipher.rsa({
// Encrypt data.
action: 'encrypt',
// Text to be encrypted.
text: 'hello',
// Base64-encoded public key used for encryption.
key:
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCx414QSP3RsYWYzf9mkBMiBAXo\n' +
'6S7Lpva1fKlcuVxjoFC1iMnzD4mC0uiL4k5MNi43J64c7dbqi3qAJjdAtuwQ6NZJ\n' +
'+Enz0RzmVFh/4yk6lmqRzuEFQqhQqSZzaLq6sq2N2G0Sv2Xl3sLvqAfe2HNm2oBw\n' +
'jBpApTJ3TeneOo6Z5QIDAQAB',
success: function(data) {
console.log(`Handling successful:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encryption failed ### ${code}:${data}`);
'jBpApTJ3TeneOo6Z5QIDAQAB',
success: function(data) {
console.log(`handling success:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encrypt fail ### ${code}:${data}`);
},
complete: function() {
console.log(`operation complete!`);
}
});
cipher.rsa({
// Decrypt data.
action: 'decrypt',
// Text to be decrypted, which is binary text encoded in Base64. The decrypted text is "hello".
text:
});
cipher.rsa({
// Decrypt data.
action: 'decrypt',
// Text to be decrypted, which is binary text encoded in Base64. The decrypted text is "hello".
text:
'EPeCFPib6ayKbA0M6oSywARvFZ8dFYfjQv3nY8ikZGtS9UHq2sLPvAfpeIzggSiCxqbWeCftP1XQ\n' +
'Sa+jEpzFlT1qoSTunBbrYzugPTajIJDTg6R1IRsF/J+mmakn0POVPvi4jCo9wqavB324Bx0Wipnc\n' +
'EU5WO0oBHo5l4x6dTpU=',
// Base64-encoded private key used for decryption.
key:
'EU5WO0oBHo5l4x6dTpU=',
// Base64-encoded private key used for decryption.
key:
'MIICXgIBAAKBgQCx414QSP3RsYWYzf9mkBMiBAXo6S7Lpva1fKlcuVxjoFC1iMnz\n' +
'D4mC0uiL4k5MNi43J64c7dbqi3qAJjdAtuwQ6NZJ+Enz0RzmVFh/4yk6lmqRzuEF\n' +
'QqhQqSZzaLq6sq2N2G0Sv2Xl3sLvqAfe2HNm2oBwjBpApTJ3TeneOo6Z5QIDAQAB\n' +
......@@ -118,18 +119,18 @@ export default {
'PKoljdXmJeS6rGgzGibstuHLrP3tcIho4+0CQD3ZFWzF/xq0jxKlrpWhnJuNCRfE\n' +
'oO6e9yNvVA8J/5oEDSOcmqSNIp4+RhbUx8InUxnCG6Ryv5aSFu71pYcKrPkCQQCL\n' +
'RUGcm3ZGTnslduB0knNF+V2ndwzDUQ7P74UXT+PjurTPhujFYiuxCEd6ORVnEOzG\n' +
'M9TORIgdH8MjIbWsGnndAkEAw9yURDaorE8IYPLF2IEn09g1uzvWPs3phDb6smVx\n' +
'M9TORIgdH8MjIbWsGnndAkEAw9yURDaorE8IYPLF2IEn09g1uzvWPs3phDb6smVx\n' +
'8GfqIdUNf+aCG5TZK/kXBF1sqcsi7jXMAf4jBlejVbSVZg==',
success: function(data) {
console.log(`Handling successful:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encryption failed ### ${code}:${data}`);
success: function(data) {
console.log(`handling success:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encrypt fail ### ${code}:${data}`);
},
complete: function() {
console.log(`operation complete!`);
}
});
}
});
}
}
```
......@@ -152,48 +153,48 @@ Encrypts or decrypts data using AES.
**Example**
```js
export default {
aes() {
cipher.aes({
// Encrypt data.
action: 'encrypt',
// Text to be encrypted.
text: 'hello',
export default {
aes() {
cipher.aes({
// Encrypt data.
action: 'encrypt',
// Text to be encrypted.
text: 'hello',
// Base64-encoded key.
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: '0',
ivLen: '16',
success: function(data) {
console.log(`Handling successful:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encryption failed ### ${code}:${data}`);
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: '0',
ivLen: '16',
success: function(data) {
console.log(`handling success:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.rsa encrypt fail ### ${code}:${data}`);
},
complete: function() {
console.log(`operation complete!`);
}
});
cipher.aes({
// Decrypt data.
action: 'decrypt',
// Text to be decrypted, which is binary text encoded in Base64.
text: '1o0kf2HXwLxHkSh5W5NhzA==',
});
cipher.aes({
// Decrypt data.
action: 'decrypt',
// Text to be decrypted, which is binary text encoded in Base64.
text: '1o0kf2HXwLxHkSh5W5NhzA==',
// Base64-encoded key.
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: '0',
ivLen: '16',
success: function(data) {
console.log(`Handling successful:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.aes encryption failed ### ${code}:${data}`);
key: 'NDM5Qjk2UjAzMEE0NzVCRjlFMkQwQkVGOFc1NkM1QkQ=',
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: '0',
ivLen: '16',
success: function(data) {
console.log(`handling success:${data.text}`);
},
fail: function(data, code) {
console.log(`### cipher.aes encrypt fail ### ${code}:${data}`);
},
complete: function() {
console.log(`operation complete!`);
}
});
});
}
}
......
......@@ -26,6 +26,9 @@ getTagInfo(): tag.TagInfo
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getTagInfo](js-apis-nfcTag.md#taggettaginfo9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -54,6 +57,9 @@ connectTag(): boolean;
Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.connect](#tagsessionconnect9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -76,12 +82,49 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag();
console.log("connectStatus: " + connectStatus);
```
### tagSession.connect<sup>9+</sup>
connect(): void;
Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
tag.getIsoDep(tagInfo).connect();
console.log("tag connect success");
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
}
```
### tagSession.reset()
reset(): void
Resets the connection to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.resetConnection](#tagsessionresetconnection9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -97,12 +140,49 @@ import tag from '@ohos.nfc.tag';
tag.getIsoDep(tagInfo).reset();
```
### tagSession.resetConnection()<sup>9+</sup>
resetConnection(): void
Resets the connection to this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
tag.getIsoDep(tagInfo).resetConnection();
console.log("tag resetConnection success");
} catch (busiError) {
console.log("tag resetConnection busiError: " + busiError);
}
```
### tagSession.isTagConnected
isTagConnected(): boolean
Checks whether the tag is connected.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.isConnected](#tagsessionisconnected9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -125,12 +205,47 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected();
console.log("isTagConnected: " + isTagConnected);
```
### tagSession.isConnected<sup>9+</sup>
isConnected(): boolean
Checks whether the tag is connected.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| boolean | Returns **true** if the tag is connected; returns **false** otherwise.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var isConnected = tag.getIsoDep(tagInfo).isConnected();
console.log("tag isConnected = " + isConnected);
} catch (busiError) {
console.log("tag isConnected busiError: " + busiError);
}
```
### tagSession.getMaxSendLength
getMaxSendLength(): number
Obtains the maximum length of the data that can be sent to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getMaxTransmitSize](#tagsessiongetmaxtransmitsize9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -152,12 +267,54 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength();
console.log("tag maxSendLen: " + maxSendLen);
```
### tagSession.getMaxTransmitSize<sup>9+</sup>
getMaxTransmitSize(): number
Obtains the maximum length of the data that can be sent to this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Maximum data length obtained. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var maxTransmitSize = tag.getIsoDep(tagInfo).getMaxTransmitSize();
console.log("tag maxTransmitSize = " + maxTransmitSize);
} catch (busiError) {
console.log("tag getMaxTransmitSize busiError: " + busiError);
}
```
### tagSession.getSendDataTimeout
getSendDataTimeout(): number
Obtains the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getTimeout](#tagsessiongettimeout9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -180,12 +337,55 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout();
console.log("tag sendDataTimeout: " + sendDataTimeout);
```
### tagSession.getTimeout<sup>9+</sup>
getTimeout(): number
Obtains the timeout period for sending data to this tag, in milliseconds.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Timeout period obtained, in milliseconds. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var timeout = tag.getIsoDep(tagInfo).getTimeout();
console.log("tag timeout = " + timeout);
} catch (busiError) {
console.log("tag getTimeout busiError: " + busiError);
}
```
### tagSession.setSendDataTimeout
setSendDataTimeout(timeout: number): boolean
Sets the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.setTimeout](#tagsessionsettimeout9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -215,12 +415,56 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs);
console.log("tag setSendDataTimeout setStatus: " + setStatus);
```
### tagSession.setTimeout<sup>9+</sup>
setTimeout(timeout: number): void
Obtains the timeout period for sending data to this tag, in milliseconds.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| timeout | number | Yes| Timeout period to set, in milliseconds. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
let timeoutMs = 700; // Change it as required.
try {
tag.getIsoDep(tagInfo).setTimeout(timeoutMs);
console.log("tag setTimeout success");
} catch (busiError) {
console.log("tag setTimeout busiError: " + busiError);
}
```
### tagSession.sendData
sendData(data: number[]): Promise<number[]>
Sends data to this tag. This API uses a promise to return the result.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -267,6 +511,9 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void
Sends data to this tag. This API uses an asynchronous callback to return the result.
> **NOTE**
> This parameter is supported since API version 7 and discarded since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9-1).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
......@@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> {
}
});
```
### tagSession.transmit<sup>9+</sup>
transmit(data: number[]): Promise<number[]>
Sends data to this tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | Yes| Data to send. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise<number[]> | Promise used to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try {
if (!tag.getIsoDep(tagInfo).isConnected()) {
tag.getIsoDep(tagInfo).connect();
}
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
return;
}
let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required.
try {
tag.getIsoDep(tagInfo).transmit(cmdData).then((response) => {
console.log("tagSession transmit Promise response: " + response);
}).catch((err)=> {
console.log("tagSession transmit Promise err: " + err);
});
} catch (busiError) {
console.log("tag transmit busiError: " + busiError);
return;
}
```
### tagSession.transmit<sup>9+</sup>
transmit(data: number[], callback: AsyncCallback<number[]>): void
Sends data to this tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | Yes| Data to send. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| callback | AsyncCallback<number[]> | Yes| Callback invoked to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try {
if (!tag.getIsoDep(tagInfo).isConnected()) {
tag.getIsoDep(tagInfo).connect();
}
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
return;
}
let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required.
try {
tag.getIsoDep(tagInfo).transmit(cmdData, (err, response)=> {
if (err) {
console.log("tagSession transmit AsyncCallback err: " + err);
} else {
console.log("tagSession transmit AsyncCallback response: " + response);
}
});
} catch (busiError) {
console.log("tag transmit busiError: " + busiError);
return;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册