iostream.stream.writestring
Writes the string and returns the number of characters written
Parameters
str | string | the string to write |
Return value
The number of bytes written: str's byte length, the same number str.len() reports. A string holding multi-byte UTF-8 text counts its encoded bytes, not its number of code points.
Errors
Throws io error if the underlying stream cannot store the full amount, for example a file opened read-only; a blob's own storage never refuses a write, so this case cannot happen on a blob.
Notes
The same method works on a file. Writing past the current len grows a blob to fit, the same as writen; writing past the end of a writable file extends it the same way.
Example
from "iostream" import blob
let b = blob(0)
println("b.writestring(\"hi\") =", b.writestring("hi")) // the number of bytes written
println("b.len() after writestring(\"hi\") =", b.len())
let e = "\xC3\xA9" // one letter, 2 UTF-8 bytes
println("b.writestring(e) =", b.writestring(e)) // counts bytes, not code points
println("b.len() after writestring(e) =", b.len())Output:
b.writestring("hi") = 2
b.len() after writestring("hi") = 2
b.writestring(e) = 2
b.len() after writestring(e) = 4See also
writestring | Writes the string and returns the number of characters written |
writeblob | Writes the given blob and returns the number of bytes written |
readblob | Reads up to size bytes and returns them as a blob |
| stream | class index |