write
write(stream, x)
Write the canonical binary representation of a value to the given stream. Returns the number of bytes written into the stream.
You can write multiple values with the same :func:write
call.
i.e. the following are equivalent:
write(stream, x, y...)
write(stream, x) + write(stream, y...)
Examples
julia> io = IOBuffer(); # Create an in-memory buffer to write to
julia> write(io, 10)
8
julia> write(io, 3.14)
8
julia> write(io, "Hello, Julia!")
14
julia> String(take!(io))
"10\x00\x00\x00\x00\x00\x00\x00\x1f\x85\xebQ\xb8!\xc7Hello, Julia!"
In this example, we create an in-memory buffer io
using IOBuffer()
. We then use the write
function to write different values to the buffer. The function returns the number of bytes written into the stream. Finally, we convert the buffer content to a string using String(take!(io))
.
Note that the write
function can be used to write multiple values with the same call. The following two examples are equivalent:
julia> io = IOBuffer();
julia> write(io, 10, 3.14, "Hello, Julia!")
30
julia> String(take!(io))
"10\x00\x00\x00\x00\x00\x00\x00\x1f\x85\xebQ\xb8!\xc7Hello, Julia!"
julia> io = IOBuffer();
julia> write(io, 10) + write(io, 3.14) + write(io, "Hello, Julia!")
30
julia> String(take!(io))
"10\x00\x00\x00\x00\x00\x00\x00\x1f\x85\xebQ\xb8!\xc7Hello, Julia!"
See Also
deserialize, eachline, eof, fd, flush, IOBuffer, ismarked, isopen, isreadonly, mark, nb_available, open, pipeline, position, read, read!, readavailable, readbytes, readbytes!, readline, redirect_stderr, redirect_stdin, reset, seek, seekend, seekstart, serialize, skip, skipchars, TextDisplay, unmark, write, writemime,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.