iostream.blob.readblob
Reads up to size bytes and returns them as a blob
from "iostream" import blob
let cargo = blob(0)
cargo.writestring("ammo")
cargo.seek(0)
println("cargo.readblob(4).as_string() =", cargo.readblob(4).as_string())Output:
cargo.readblob(4).as_string() = ammoParameters
size | int | the largest number of bytes to read |
Return value
See iostream.stream.readblob for the generic contract.
Errors
Throws no data left to read when the cursor is already at len and nothing can be read.
Notes
size is capped against len, not against what is left after the cursor, so asking for more than remains is not an error by itself: fewer bytes than requested come back in the result blob. Only asking with nothing left throws.
Example
from "iostream" import blob
let b = blob(4)
b.writen(0x01020304, 'i')
b.seek(3) // only 1 byte remains before len
let got = b.readblob(4) // asking for more than remains is not an error
println("got.len() =", got.len()) // fewer bytes than asked for came back
try {
b.readblob(1) // now nothing at all remains
} catch (e) {
println("b.readblob(1) throws:", e)
}Output:
got.len() = 1
b.readblob(1) throws: no data left to readSee also
readblob | Reads up to size bytes and returns them as a blob |
writeblob | Writes the given blob and returns the number of bytes written |
as_string | Returns the blob contents as a string |
| blob | class index |