Object - io : ReadableByteChannel

ReadableByteChannel represents an input resource (i.e file). which could be used to source bytes.

Methods

Source bytes from a given input/output resource.
Encodes a given ReadableByteChannel using the Base64 encoding scheme.
Decodes a given ReadableByteChannel using the Base64 encoding scheme.
Closes a given ReadableByteChannel.

read

(int nBytes)

returns byte[] | Error

Source bytes from a given input/output resource. The number of bytes returned will be < 0 if the file reached its end. 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.

 byte[]|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

base64Encode

()

returns ReadableByteChannel | Error

Encodes a given ReadableByteChannel using the Base64 encoding scheme.

 ReadableByteChannel|Error encodedChannel = readableByteChannel.base64Encode();

base64Decode

()

returns ReadableByteChannel | Error

Decodes a given ReadableByteChannel using the Base64 encoding scheme.

 ReadableByteChannel|Error encodedChannel = readableByteChannel.base64Decode();

close

()

returns Error?

Closes a given ReadableByteChannel.

 io:Error? err = readableByteChannel.close();

  • Return Type

    (Error?)
  • Will return () if there is no error