ByteArrayStream Example
The following is an example of writing data to and reading data from a stream using ByteArrayStream.
import std.io.*
main(): Unit {
let arr1 = "test case".toArray()
let byteArrayStream = ByteArrayStream()
/* Writes the data in **arr1** to the stream. */
byteArrayStream.write(arr1)
/* Reads a piece of data of 4 bytes to **arr2**. */
let arr2 = Array<Byte>(4, item: 0)
byteArrayStream.read(arr2)
println(String.fromUtf8(arr2))
/* Points the flow index to the start point. */
byteArrayStream.seek(Begin(0))
/* Reads all data in the stream. */
let arr3 = byteArrayStream.readToEnd()
println(String.fromUtf8(arr3))
/* Points the flow index to the letter c. */
byteArrayStream.seek(End(-4))
/* Reads the remaining data in the stream. */
let str = byteArrayStream.readString()
println(str)
}
Running result:
test
test case
case