Class ByteString

(builtin) 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.


define each_byte(fn: Function(Byte))

Call fn for each Byte within the given ByteString.

define encode(encode: *String = "error"): 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.

define size: Integer

Return the number of Byte values within self.

define slice(start: *Integer = 0, stop: *Integer = -1): 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:

  • Either start or stop is out of range.
  • The start is larger than the stop (reversed).