Class: WritableByteChannel

WritableByteChannel represents an output resource (i.e file) which could be used to sink bytes A file path can be used to obtain an io:WritableByteChannel. An io:WritableByteChannel can only be obtained using the following method or by providing a native implementation. It cannot be instantiated. io:openWritableFile("./files/sample.txt") - used to obtain an io:WritableByteChannel from a given file path

Methods

write

Sinks bytes from a given input/output resource.

close

Closes the byte channel.

write

function write(byte[ ] content, int offset) returns int | Error
Isolated Function

Sinks bytes from a given input/output resource.

This is an asynchronous operation. The method might return before writing all the content.

1int|io:Error result = writableByteChannel.write(record, 0);

Parameters

  • content byte[ ]
  • Block of bytes to be written

  • offset int
  • Offset of the provided content, which needs to be kept when writing bytes

Return Type

(int | Error)

Number of bytes written or else an io:Error

close

function close() returns Error?
Isolated Function

Closes the byte channel. After a channel is closed, any further writing operations will cause an error.

1io:Error err = writableByteChannel.close();

Return Type

(Error?)

An io:Error or else ()