File
The File object that access to an open file on filesystem.
See
Accessors
isDisposed
Get Signature
get isDisposed(): boolean;
File is already been closed.
Example
const file = await Rsvim.fs.open("README.md");
if (!file.isDisposed()) {
file.close();
}
Returns
boolean
Methods
close()
close(): void;
Close the file.
Returns
void
Example
const file = await Rsvim.fs.open("README.md");
// do work with the `file` object
file.close();
// Or
using file = await Rsvim.fs.open("README.md");
// do work with the `file` object
[dispose]()
dispose: void;
Close the file with using without close API.
Returns
void
Example
using file = await Rsvim.fs.open("README.md");
// do work with the `file` object
See
read()
read(buf): Promise<number>;
Read a file into a buffer.
It is not guaranteed that the full buffer will be read in a single call.
Parameters
| Parameter | Type | Description |
|---|---|---|
| Read bytes into buffer. |
Returns
Promise<number>
It resolves to either the number of bytes read during the operation or 0(EOF) if there was no more to read.
Throws
Throws TypeError if buf is not a Uint8Array.
Example
using file = await Rsvim.fs.open("README.md");
const buf = new Uint8Array(100);
const n = await file.read(buf); // read 11 bytes
const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
readSync()
readSync(buf): number;
Sync version of read.
Parameters
| Parameter | Type | Description |
|---|---|---|
| Same with read. |
Returns
number
Same with read.
Throws
Same with read.
Example
using file = await Rsvim.fs.open("README.md");
const buf = new Uint8Array(100);
const n = file.readSync(buf); // read 11 bytes
const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
write()
write(buf): Promise<number>;
Write a buffer into a file.
It is not guaranteed that the full buffer will be written in a single call.
Parameters
| Parameter | Type | Description |
|---|---|---|
| Read bytes into buffer. |
Returns
Promise<number>
It resolves to either the number of bytes written during the operation or 0 if there was nothing to write.
Throws
Throws TypeError if buf is not a Uint8Array.
Example
using file = await Rsvim.fs.open("README.md", {write:true,create:true});
const buf = new TextEncoder().encode("hello world");
const n = await file.write(buf); // write 11 bytes
writeSync()
writeSync(buf): number;
Sync version of write.
Parameters
| Parameter | Type | Description |
|---|---|---|
| Same with write. |
Returns
number
Same with write.
Throws
Same with write.
Example
using file = await Rsvim.fs.open("README.md", {write:true,create:true});
const buf = new TextEncoder().encode("hello world");
const n = file.writeSync(buf); // write 11 bytes