Quirrel4.41.0

iostream.blob.writeblob

Method of blob, from module "iostream"
instance.writeblob(blob: instance): int

Writes the given blob and returns the number of bytes written

examples/iostream/blob/writeblob-basic.nut
from "iostream" import blob

let src = blob(0)
src.writestring("ammo")

let dst = blob(0)
println("dst.writeblob(src) =", dst.writeblob(src))
println("dst.as_string() =", dst.as_string())
Output:
dst.writeblob(src) = 4
dst.as_string() = ammo

Parameters

blobinstancethe source blob; all of it is written

Return value

See iostream.stream.writeblob for the generic contract.

Notes

Writing past the current len grows this blob to fit, the same as writen; it is never an error to write more than currently fits.

Example

examples/iostream/blob/writeblob.nut
from "iostream" import blob

let src = blob(3)
src[0] = 7; src[1] = 8; src[2] = 9

let dst = blob(0)        // empty: writing to it must grow it
println("dst.writeblob(src) =", dst.writeblob(src))
println("dst.len() =", dst.len())
println("dst[0], dst[1], dst[2] =", $"{dst[0]},{dst[1]},{dst[2]}")
Output:
dst.writeblob(src) = 3
dst.len() = 3
dst[0], dst[1], dst[2] = 7,8,9

See also

writeblobWrites the given blob and returns the number of bytes written
readblobReads up to size bytes and returns them as a blob
writestringWrites the string and returns the number of characters written
blobclass index