io.file.writeblob
Writes the given blob and returns the number of bytes written
from "io" import file
from "iostream" import blob
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_writeblob_basic.tmp"
let cargo = blob(0)
cargo.writestring("ammo")
let f = file(path, "wb")
println("f.writeblob(cargo) =", f.writeblob(cargo))
f.close()
remove(path)Output:
f.writeblob(cargo) = 4Parameters
blob | instance | the source blob; all of it is written |
Return value
See iostream.stream.writeblob for the generic contract.
Errors
Throws the stream is invalid once the file has been closed.
Notes
Writing past the current end of the file grows it, the same as writen; it is never an error to write more than currently fits, since a real file has no fixed capacity to run into.
Example
from "io" import file
from "iostream" import blob
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_writeblob.tmp"
let b = blob(3)
b.writen(0x41, 'b')
b.writen(0x42, 'b')
b.writen(0x43, 'b')
let f = file(path, "wb")
println("f.writeblob(b) =", f.writeblob(b)) // all of it goes, and the count written comes back
f.close()
let r = file(path, "rb")
println("r.len() =", r.len())
r.close()
remove(path)Output:
f.writeblob(b) = 3
r.len() = 3See also
writeblob | Writes the given blob and returns the number of bytes written |
readblob | Reads up to size bytes and returns them as a blob |
writestring | Writes the string and returns the number of characters written |
| file | class index |