提交 c5906728 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 f9cf0d1c
...@@ -20,7 +20,7 @@ Defines a file metadata object, which includes the application name and file URI ...@@ -20,7 +20,7 @@ Defines a file metadata object, which includes the application name and file URI
**System capability**: SystemCapability.FileManagement.StorageService.Backup **System capability**: SystemCapability.FileManagement.StorageService.Backup
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------- | | ---------- | ------ | ---- | ---------------------------------------------------------------------------------------------- |
| bundleName | string | Yes | Bundle name of the application, which can be obtained by using the method provided by [bundle.BundleInfo](js-apis-bundle-BundleInfo.md). | | bundleName | string | Yes | Bundle name of the application, which can be obtained by using the method provided by [bundle.BundleInfo](js-apis-bundle-BundleInfo.md). |
| uri | string | Yes | Name of the file in the application sandbox.<br>Currently, the URI has not been upgraded to the standard format. It can consist of digits (0–9), letters (a–z and A–Z), underscores (_), and period (.) only.| | uri | string | Yes | Name of the file in the application sandbox.<br>Currently, the URI has not been upgraded to the standard format. It can consist of digits (0–9), letters (a–z and A–Z), underscores (_), and period (.) only.|
...@@ -63,15 +63,16 @@ Called when the server sends a file to the client. If the file is sent successfu ...@@ -63,15 +63,16 @@ Called when the server sends a file to the client. If the file is sent successfu
> **NOTE** > **NOTE**
> >
> The **File** returned by **AsyncCallback** is the file.backup.[File](#file). The returned file belongs to the backup service. Once the file is closed, the backup service shall clear the resources used by the file. However, the client must close the file handle first. > The **File** returned by **AsyncCallback** is the file.backup.[File](#file). The returned file belongs to the backup service. Once the file is closed, the backup service shall clear the resources used by the file at the proper time. However, the client must close the file handle first.
**System capability**: SystemCapability.FileManagement.StorageService.Backup **System capability**: SystemCapability.FileManagement.StorageService.Backup
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -103,8 +104,9 @@ onBundleBegin : AsyncCallback&lt;string&gt; ...@@ -103,8 +104,9 @@ onBundleBegin : AsyncCallback&lt;string&gt;
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -134,8 +136,9 @@ Called when the backup or restoration of an application ends. If the backup or r ...@@ -134,8 +136,9 @@ Called when the backup or restoration of an application ends. If the backup or r
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -165,8 +168,9 @@ Called when the backup or restoration of all bundles ends. If the backup or rest ...@@ -165,8 +168,9 @@ Called when the backup or restoration of all bundles ends. If the backup or rest
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -214,14 +218,15 @@ Obtains a JSON file that describes local capabilities. This API uses an asynchro ...@@ -214,14 +218,15 @@ Obtains a JSON file that describes local capabilities. This API uses an asynchro
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | --------------------- | | -------- | ------------------------------------------ | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;[FileData](#filedata)&gt; | Yes | Callback invoked to return the result. If the file is obtained, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;[FileData](#filedata)&gt; | Yes | Callback invoked to return the result. If the file is obtained, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -276,14 +281,15 @@ Obtains a JSON file that describes local capabilities. This API uses a promise t ...@@ -276,14 +281,15 @@ Obtains a JSON file that describes local capabilities. This API uses a promise t
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------- | ------------------ | | ------------------------------------ | --------------------------------------------------- |
| Promise&lt;[FileData](#filedata)&gt; | Promise used to return the **FileData** of the JSON file obtained.| | Promise&lt;[FileData](#filedata)&gt; | Promise used to return the **FileData** of the JSON file obtained.|
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
...@@ -294,6 +300,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -294,6 +300,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
async function getLocalCapabilities() {
try { try {
let fileData = await backup.getLocalCapabilities(); let fileData = await backup.getLocalCapabilities();
console.info('getLocalCapabilities success'); console.info('getLocalCapabilities success');
...@@ -301,6 +308,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -301,6 +308,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod
} catch (err) { } catch (err) {
console.error('getLocalCapabilities failed with err: ' + err); console.error('getLocalCapabilities failed with err: ' + err);
} }
}
``` ```
The following is an example of the file obtained: The following is an example of the file obtained:
...@@ -345,7 +353,7 @@ A constructor used to create a **SessionBackup** instance. ...@@ -345,7 +353,7 @@ A constructor used to create a **SessionBackup** instance.
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let sessionBackup = new backup.SessionBackup({ let generalCallbacks = backup.GeneralCallbacks({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
...@@ -375,6 +383,7 @@ A constructor used to create a **SessionBackup** instance. ...@@ -375,6 +383,7 @@ A constructor used to create a **SessionBackup** instance.
console.info('service died'); console.info('service died');
} }
}); });
let sessionBackup = new backup.SessionBackup(generalCallbacks);
``` ```
### appendBundles ### appendBundles
...@@ -397,8 +406,9 @@ Appends the applications whose data needs to be backed up. Currently, the obtain ...@@ -397,8 +406,9 @@ Appends the applications whose data needs to be backed up. Currently, the obtain
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
...@@ -409,7 +419,39 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -409,7 +419,39 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
import fs from '@ohos.file.fs';
let sessionBackup = new backup.SessionBackup({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
try { try {
sessionBackup.appendBundles(['com.example.hiworld'], (err) => { sessionBackup.appendBundles(['com.example.hiworld'], (err) => {
if (err) { if (err) {
...@@ -447,8 +489,9 @@ Appends the applications whose data needs to be backed up. Currently, the obtain ...@@ -447,8 +489,9 @@ Appends the applications whose data needs to be backed up. Currently, the obtain
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
...@@ -460,12 +503,45 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -460,12 +503,45 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
import fs from '@ohos.file.fs';
let sessionBackup = new backup.SessionBackup({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
async function appendBundles() {
try { try {
await sessionBackup.appendBundles(['com.example.hiworld']); await sessionBackup.appendBundles(['com.example.hiworld']);
console.info('appendBundles success'); console.info('appendBundles success');
} catch (err) { } catch (err) {
console.error('appendBundles failed with err: ' + err); console.error('appendBundles failed with err: ' + err);
} }
}
``` ```
## SessionRestore ## SessionRestore
...@@ -492,7 +568,7 @@ A constructor used to create a **SessionRestore** instance. ...@@ -492,7 +568,7 @@ A constructor used to create a **SessionRestore** instance.
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({ let generalCallbacks = backup.GeneralCallbacks({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
...@@ -518,10 +594,11 @@ A constructor used to create a **SessionRestore** instance. ...@@ -518,10 +594,11 @@ A constructor used to create a **SessionRestore** instance.
} }
console.info('onAllBundlesEnd success'); console.info('onAllBundlesEnd success');
}, },
onRestoreServiceDied: () => { onBackupServiceDied: () => {
console.info('service died'); console.info('service died');
} }
}); });
let sessionRestore = new backup.SessionRestore(generalCallbacks);
``` ```
### appendBundles ### appendBundles
...@@ -550,8 +627,9 @@ Appends the applications whose data needs to be restored. Currently, the obtaine ...@@ -550,8 +627,9 @@ Appends the applications whose data needs to be restored. Currently, the obtaine
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
...@@ -563,6 +641,38 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -563,6 +641,38 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
async function appendBundles() {
try { try {
let fileData = await backup.getLocalCapabilities(); let fileData = await backup.getLocalCapabilities();
console.info('getLocalCapabilities success'); console.info('getLocalCapabilities success');
...@@ -573,7 +683,8 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -573,7 +683,8 @@ For details about the error codes, see [File Management Error Codes](../errorcod
console.info('appendBundles success'); console.info('appendBundles success');
}); });
} catch (err) { } catch (err) {
console.error('appendBundles failed with err: ' + err); console.error('getLocalCapabilities failed with err: ' + err);
}
} }
``` ```
...@@ -608,8 +719,9 @@ Appends the applications whose data needs to be restored. Currently, the obtaine ...@@ -608,8 +719,9 @@ Appends the applications whose data needs to be restored. Currently, the obtaine
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
...@@ -621,13 +733,46 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -621,13 +733,46 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
async function appendBundles() {
try { try {
let fileData = await backup.getLocalCapabilities(); let fileData = await backup.getLocalCapabilities();
console.info('getLocalCapabilities success'); console.info('getLocalCapabilities success');
await sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld']); await sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld']);
console.info('appendBundles success'); console.info('appendBundles success');
} catch (err) { } catch (err) {
console.error('appendBundles failed with err: ' + err); console.error('getLocalCapabilities failed with err: ' + err);
}
} }
``` ```
...@@ -658,8 +803,9 @@ Obtains the handle of the shared file from the service. This API uses an asynchr ...@@ -658,8 +803,9 @@ Obtains the handle of the shared file from the service. This API uses an asynchr
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
...@@ -668,7 +814,37 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -668,7 +814,37 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
try { import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
sessionRestore.getFileHandle({ sessionRestore.getFileHandle({
bundleName: "com.example.hiworld", bundleName: "com.example.hiworld",
uri: "test.txt" uri: "test.txt"
...@@ -678,9 +854,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -678,9 +854,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod
} }
console.info('getFileHandle success'); console.info('getFileHandle success');
}); });
} catch (err) {
console.error('getFileHandle failed with err: ' + err);
}
``` ```
### getFileHandle ### getFileHandle
...@@ -715,8 +888,9 @@ Obtains the handle of the shared file from the service. This API uses a promise ...@@ -715,8 +888,9 @@ Obtains the handle of the shared file from the service. This API uses a promise
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
...@@ -725,6 +899,38 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -725,6 +899,38 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => {
if (err) {
console.error('onFileReady failed with err: ' + err);
}
console.info('onFileReady success');
fs.closeSync(file.fd);
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
async function getFileHandle() {
try { try {
await sessionRestore.getFileHandle({ await sessionRestore.getFileHandle({
bundleName: "com.example.hiworld", bundleName: "com.example.hiworld",
...@@ -734,6 +940,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -734,6 +940,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod
} catch (err) { } catch (err) {
console.error('getFileHandle failed with err: ' + err); console.error('getFileHandle failed with err: ' + err);
} }
}
``` ```
### publishFile ### publishFile
...@@ -762,8 +969,9 @@ Publishes **FileMeta** to the backup service to indicate that the file content i ...@@ -762,8 +969,9 @@ Publishes **FileMeta** to the backup service to indicate that the file content i
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
...@@ -772,14 +980,17 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -772,14 +980,17 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
try { import fs from '@ohos.file.fs';
let g_session;
function createSessionRestore() {
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
} }
console.info('onFileReady success'); console.info('onFileReady success');
fs.closeSync(file.fd); fs.closeSync(file.fd);
sessionRestore.publishFile({ g_session.publishFile({
bundleName: file.bundleName, bundleName: file.bundleName,
uri: file.uri uri: file.uri
}, (err) => { }, (err) => {
...@@ -788,10 +999,32 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -788,10 +999,32 @@ For details about the error codes, see [File Management Error Codes](../errorcod
} }
console.info('publishFile success'); console.info('publishFile success');
}); });
},
onBundleBegin: (err, bundleName) => {
if (err) {
console.error('onBundleBegin failed with err: ' + err);
} }
} catch (err) { console.info('onBundleBegin success');
console.error('publishFile failed with err: ' + err); },
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
} }
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
return sessionRestore;
}
g_session = createSessionRestore();
``` ```
### publishFile ### publishFile
...@@ -825,8 +1058,9 @@ Publishes **FileMeta** to the backup service to indicate that the file content i ...@@ -825,8 +1058,9 @@ Publishes **FileMeta** to the backup service to indicate that the file content i
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| -------- | ----------------------- |
| 13600001 | IPC error | | 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
...@@ -835,20 +1069,49 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -835,20 +1069,49 @@ For details about the error codes, see [File Management Error Codes](../errorcod
**Example** **Example**
```js ```js
try { import fs from '@ohos.file.fs';
let g_session;
async function publishFile(file)
{
await g_session.publishFile({
bundleName: file.bundleName,
uri: file.uri
});
}
function createSessionRestore() {
let sessionRestore = new backup.SessionRestore({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
} }
console.info('onFileReady success'); console.info('onFileReady success');
fs.closeSync(file.fd); fs.closeSync(file.fd);
await sessionRestore.publishFile({ publishFile(file);
bundleName: file.bundleName,
uri: file.uri
});
console.info('publishFile success'); console.info('publishFile success');
}, },
} catch (err) { onBundleBegin: (err, bundleName) => {
console.error('publishFile failed with err: ' + err); if (err) {
console.error('onBundleBegin failed with err: ' + err);
}
console.info('onBundleBegin success');
},
onBundleEnd: (err, bundleName) => {
if (err) {
console.error('onBundleEnd failed with err: ' + err);
}
console.info('onBundleEnd success');
},
onAllBundlesEnd: (err) => {
if (err) {
console.error('onAllBundlesEnd failed with err: ' + err);
}
console.info('onAllBundlesEnd success');
},
onBackupServiceDied: () => {
console.info('service died');
}
});
return sessionRestore;
} }
g_session = createSessionRestore();
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册