Class: ReadableByteChannel
ReadableByteChannel represents an input resource (i.e file), which could be used to source bytes.
A file path or an in-memory byte
array can be used to obtain an io:ReadableByteChannel
.
An io:ReadableByteChannel
does not support initialization, and it should be obtained using the following methods or implemented natively.
io:openReadableFile("./files/sample.txt")
- used to obtain an io:ReadableByteChannel
from a given file path
io:createReadableChannel(byteArray)
- used to obtain an io:ReadableByteChannel
from a given byte
array
Methods
read | Source bytes from a given input resource. |
readAll | Read all content of the channel as a |
blockStream | Return a block stream that can be used to read all |
base64Encode | Encodes a given |
base64Decode | Decodes a given Base64 encoded |
close | Closes the |
read
Source bytes from a given input resource.
This operation will be asynchronous in which the total number of required bytes might not be returned at a given
time. An io:EofError
will return once the channel reaches the end.
1byte[]|io:Error result = readableByteChannel.read(1000);
Parameters
- nBytes int
A positive integer. Represents the number of bytes, which should be read
Return Type
(byte[ ] | Error)Content (the number of bytes) read, an EofError
once the channel reaches the end or else an io:Error
blockStream
Return a block stream that can be used to read all byte
blocks as a stream.
1stream<io:Block, io:Error>|io:Error result = readableByteChannel.blockStream();
Parameters
- blockSize int
A positive integer. Size of the block.
base64Encode
function base64Encode() returns ReadableByteChannel | Error
Encodes a given io:ReadableByteChannel
using the Base64 encoding scheme.
1io:ReadableByteChannel|Error encodedChannel = readableByteChannel.base64Encode();
base64Decode
function base64Decode() returns ReadableByteChannel | Error
Decodes a given Base64 encoded io:ReadableByteChannel
.
1io:ReadableByteChannel|Error encodedChannel = readableByteChannel.base64Decode();