Class ByteString

The ByteString class represents a bag of bytes. A ByteString may have '\0' values embedded within it. It may also have data that is not valid as utf-8. The ByteString class currently does not support any primitive operations.

public static define create(size: Integer, byte: *Byte): ByteString

Create a new ByteString of a given size.

byte is used to populate the returned ByteString. By default, it is \0.

public define each_byte(fn: Function(Byte))

Call fn for each Byte within the given ByteString.

public define encode(encode: *String): Option[String]

Attempt to transform the given ByteString into a String. The action taken depends on the value of encode.

If encode is "error", then invalid utf-8 or embedded '\0' values within self will result in None.

public define replace_bytes(index: Integer, bytes: ByteString, start: *Integer, stop: *Integer): self

Replaces a section of self, starting at index, with the contents of bytes.

If a negative index is given, it is treated as an offset from the end of self, with -1 being considered the last element.

If start and stop are provided, only the section between them in bytes will be used (if only start is provided, the section will include the remainder of self). They may also be negative.

This method returns self, so that it can be chained with others.

public define size: Integer

Return the number of Byte values within self.

public define slice(start: *Integer, stop: *Integer): ByteString

Create a new ByteString copying a section of self from start to stop.

If a negative index is given, it is treated as an offset from the end of self, with -1 being considered the last element.

On error, this generates an empty ByteString. Error conditions are: