readavailable

readavailable(stream)

Read all available data on the stream, blocking the task only if no data is available. The result is a Vector{UInt8,1}.

Examples

julia> stream = IOBuffer("Hello, World!")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=13, maxsize=Inf, ptr=1, mark=-1)

julia> readavailable(stream)
13-element Vector{UInt8}:
 0x48
 0x65
 0x6c
 0x6c
 0x6f
 0x2c
 0x20
 0x57
 0x6f
 0x72
 0x6c
 0x64
 0x21

This example demonstrates the usage of the readavailable function on an IO stream. The stream in this case is an IOBuffer initialized with the string "Hello, World!". The function reads all the available data from the stream and returns it as a Vector{UInt8}.

Note that the actual UInt8 values in the result may vary depending on the content of the stream.

Common mistake example:

julia> stream = IOBuffer("Hello, World!")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=13, maxsize=Inf, ptr=1, mark=-1)

julia> readavailable(stream, 5)
ERROR: MethodError: no method matching readavailable(::IOBuffer, ::Int64)

In this example, the user attempted to provide an additional argument 5 to the readavailable function. However, the function only takes one argument, which is the stream to read from. Make sure to use the correct number of arguments when using readavailable.

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.

*Required Field
Details

Checking you are not a robot: