Constructor
new FileStream(file, mode)
Construct a file stream from an File.
This will create a wrapper stream that will route read() and write() to the FileChannel
Parameters:
Name | Type | Description |
---|---|---|
file |
IFile | The File that will be used to get the read/write stream |
mode |
string | The mode "r" for read "rw" for write |
Classes
Methods
(async) canRead() → {Promise.<boolean>}
True if stream can read from file.
Returns:
True if it can read
- Type
- Promise.<boolean>
(async) canSeek() → {Promise.<boolean>}
True if stream can seek.
Returns:
True if it can seek
- Type
- Promise.<boolean>
(async) canWrite() → {Promise.<boolean>}
True if stream can write to file.
Returns:
True if it can write
- Type
- Promise.<boolean>
(async) close()
Close this stream and associated resources.
Throws:
IOException Thrown if there is an IO error.
(async) flush()
Flush the buffers to the associated file.
(async) getLength() → {Promise.<number>}
Get the length of the stream. This is the same as the file size.
Returns:
The length
- Type
- Promise.<number>
(async) getPosition() → {Promise.<number>}
Get the current position of the stream.
Throws:
IOException Thrown if there is an IO error.
Returns:
The position
- Type
- Promise.<number>
(async) read(buffer, offset, count) → {Promise.<number>}
Read data from the file stream into the buffer provided.
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Uint8Array | The buffer to write the data. |
offset |
number | The offset of the buffer to start writing the data. |
count |
number | The maximum number of bytes to read from. |
Throws:
IOException Thrown if there is an IO error.
Returns:
The number of bytes read
- Type
- Promise.<number>
(async) seek(offset, origin) → {number}
Seek to the offset provided.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | The position to seek to. |
origin |
SeekOrigin | The type of origin SeekOrigin |
Throws:
IOException Thrown if there is an IO error.
Returns:
The new position after seeking.
- Type
- number
(async) setLength(value)
Set the length of the stream. This is applicable for write streams only.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | The new length. |
Throws:
IOException Thrown if there is an IO error.
(async) setPosition(value)
Set the current position of the stream.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | The new position. |
Throws:
IOException Thrown if there is an IO error.
(async) write(buffer, offset, count)
Write the data from the buffer provided into the stream.
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Uint8Array | The buffer to read the data from. |
offset |
number | The offset of the buffer to start reading the data. |
count |
number | The maximum number of bytes to read from the buffer. |
Throws:
IOException Thrown if there is an IO error.