iostream.stream.writeblob
Writes the given blob and returns the number of bytes written
from "iostream" import blob
let src = blob(0)
src.writestring("gold")
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() = goldParameters
blob | instance | the source blob; all of it is written |
Return value
The number of bytes written, which is always blob.len().
Errors
Throws invalid parameter when blob is an instance but not a blob. Passing something that is not an instance, such as a number or a string, is rejected earlier by the declared parameter type and never reaches this message.
writeblob also 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 src = blob(3)
src.writen(1, 'c')
src.writen(2, 'c')
src.writen(3, 'c')
let dst = blob(0)
println("dst.writeblob(src) =", dst.writeblob(src)) // returns the number of bytes written
println("dst.len() =", dst.len())
class Foo {}
try { dst.writeblob(Foo()) } catch (e) { println("dst.writeblob(Foo()) throws:", e) } // an instance, but not a blobOutput:
dst.writeblob(src) = 3
dst.len() = 3
dst.writeblob(Foo()) throws: invalid parameterSee 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 |
| stream | class index |