update README.md.

Signed-off-by: gsl_1234 <gaoshunli@huawei.com>
This commit is contained in:
gsl_1234 2022-10-12 03:35:01 +00:00 committed by Gitee
parent b56635902e
commit 3caee918f8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -172,7 +172,7 @@ The I/O APIs provided by the Distributed File subsystem can be classified into t
import fileio from '@OHOS.distributedfile.fileio';
try {
var ss = fileio.Stream.createStreamSync("tmp", "r")
var ss = fileio.createStreamSync("tmp", "r")
buf = new ArrayBuffer(4096)
ss.readSync(buf)
console.log(String.fromCharCode.apply(null, new Uint8Array(buf)))
@ -184,37 +184,6 @@ The I/O APIs provided by the Distributed File subsystem can be classified into t
```
- Asynchronous programming model: Promise
In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is not passed as their input parameter are implemented as the Promise asynchronous model. The Promise asynchronous model is one of the OHOS standard asynchronous models. When an asynchronous API using the Promise model is called, the API returns a Promise object while executing the concerned task asynchronously. The Promise object represents the asynchronous operation result. When there is more than one result, the results are returned as properties of the Promise object.
In the following example, a Promise chain is used to open a file stream in read-only mode, attempt to read the first 4096 bytes of the file, display the length of the content read, and then close the file:
```
import fileio from '@OHOS.distributedfile.fileio';
try {
let openedStream
fileio.Stream.createStream("test.txt", "r")
.then(function (ss) {
openedStream = ss;
return ss.read(new ArrayBuffer(4096))
})
.then(function (res) {
console.log(res.bytesRead);
console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer)))
return openedStream.close()
})
.then(function (undefined) {
console.log("Stream is closed")
})
.catch(function (e) {
console.log(e)
})
} catch (e) {
console.log(e)
}
```
- Asynchronous programming model: Callback
@ -227,7 +196,7 @@ The I/O APIs provided by the Distributed File subsystem can be classified into t
import fileio from '@OHOS.distributedfile.fileio';
try {
fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
fileio.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
if (!err) {
ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) {
if (!err) {