| close --clear-buffered/bool= -> none | Closes this reader. |
|---|---|
| is-closed -> bool | Whether this reader is closed. |
| operator == other/any -> bool | Whether this object is equal to the other. |
| stringify -> string | Stringifies this object. |
| clear -> none | Clears any buffered data. |
| ensure-buffered n/int -> none | Ensures that at least n bytes are buffered. |
| try-ensure-buffered n/int -> bool | Attempts to buffer at least n bytes. |
| is-buffered n/int -> bool | Whether n bytes are available in the internal buffer. |
| buffer-all -> none | Buffers all the remaining data of this reader. |
| buffered-size -> int | The amount of buffered data. |
| processed -> int | The number of bytes that have been produced by this reader so far. |
| skip n/int -> none | Skips over the next n bytes. |
| skip-up-to delimiter/int --to/int= --throw-if-absent/bool= -> int | Skips all bytes up to and including the given delimiter. |
| peek-byte n/int= -> int | Gets the n th byte from our current position. |
| peek-bytes n/int -> ByteArray | Gets the n next bytes. |
| read-all -> ByteArray | Reads the rest of the data and returns it. |
| drain -> none | Drains the reader without buffering or returning the data. |
| index-of byte/int --to/int= --throw-if-absent/bool= -> int | Searches forwards for the byte. |
| read --max-size/int= -> ByteArray | Reads from the reader. |
| read-string n/int -> string | Reads the first n bytes as a string. |
| read-string --max-size/int= -> string | Reads at most max-size bytes as a string. |
| read-byte -> int | Reads the first byte. |
| read-bytes n/int -> ByteArray | Reads the first n bytes from the reader. |
| peek-string n/int -> string | Gets the first n bytes and returns them as string. |
| read-line --keep-newline/bool= -> string | Reads a line as a string. |
| read-lines --keep-newlines/bool= -> List | Reads the remaining data as lines. |
| do --lines/True --keep-newlines/bool= [block] -> none | Calls the given block for each remaining line. |
| read-string-up-to delimiter/int -> string | Reads the string before the delimiter. |
| read-bytes-up-to delimiter/int -> ByteArray | Reads the bytes before the delimiter. |
| unget value/ByteArray --hand-over/bool= -> none | Prepends the values in the value byte-array. |
| little-endian -> EndianReader | Provides endian-aware functions to read from this instance. |
| big-endian -> EndianReader | Provides endian-aware functions to read from this instance. |
| content-size -> int | The total number of bytes that this reader can produce. |
import io
main:
reader := io.Reader #[0x12, 0x34, 0x56, 0x78]
number := reader.big-endian.read-int32
// The most significant byte 0x12 was at index 0.
print "0x$(%x number)" // => 0x12345678
import io
main:
reader := io.Reader #[0x78, 0x56, 0x34, 0x12]
number := reader.little-endian.read-int32
// The least significant byte 0x78 was at index 0.
print "0x$(%x number)" // => 0x12345678
class Pin:
number/int
constructor .number:
operator == other:
if other is not Pin: return false
return number == other.number
hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).
class MyReader implements Reader:
read -> ByteArray?: return "hellø".to-byte-array
main:
reader := BufferedReader MyReader
print
reader.peek-string 6 // >> Hellø
print
reader.peek-string 5 // >> Error!
read-exactly-or-drain reader/BufferedReader n/int -> ByteArray?:
if can-ensure n: return reader.read-bytes n
reader.buffer-all
if reader.buffered == 0: return null
return reader.read-bytes reader.buffered
class MyReader implements Reader:
read -> ByteArray?: return "hellø".to-byte-array
main:
reader := BufferedReader MyReader
print
reader.read-string 6 // >> Hellø
print
reader.read-string 5 // >> Error!