Quirrel4.41.0

iostream.blob.constructor

Method of blob, from module "iostream"
constructor([size: int]): instance

Creates a blob of the given size (default 0)

Parameters

sizeintnumber of bytes to allocate optional

Errors

Throws cannot create blob with negative size when size is negative.

Notes

size defaults to 0, which makes an empty blob rather than failing; writing to it later grows it, as described on writen.

Example

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

let empty = blob()          // size defaults to 0
println("empty.len() =", empty.len())

let b = blob(3)             // new bytes are zero-filled
println("b[0], b[1], b[2] =", $"{b[0]},{b[1]},{b[2]}")

try {
  blob(-1)
} catch (e) {
  println("blob(-1) throws:", e)
}
Output:
empty.len() = 0
b[0], b[1], b[2] = 0,0,0
blob(-1) throws: cannot create blob with negative size

See also

resizeResizes the blob to the given size
lenReturns the stream length
tellReturns the current stream position
blobclass index