nb_available

nb_available(stream)

Returns the number of bytes available for reading before a read from this stream or buffer will block.

Examples

"""
nb_available(stream)

Returns the number of bytes available for reading before a read from this stream or buffer will block.
"""

# Example 1: Check available bytes in a file stream
stream = open("data.txt", "r")
available_bytes = nb_available(stream)
println("Available bytes: $available_bytes")
close(stream)

# Example 2: Check available bytes in a buffer
buffer = IOBuffer("Hello, World!")
available_bytes = nb_available(buffer)
println("Available bytes: $available_bytes")

In the above code examples, we demonstrate the usage of nb_available function in Julia.

  1. Check available bytes in a file stream:

    • First, we open a file stream using open function and specify the file name and mode ("r" for reading).
    • Then, we pass the stream to nb_available function to get the number of available bytes for reading.
    • Finally, we print the result.
    • It's important to close the stream using close function after we are done with it.
  2. Check available bytes in a buffer:
    • We create an IOBuffer using IOBuffer("Hello, World!"), which initializes the buffer with the given string.
    • Then, we pass the buffer to nb_available function to get the number of available bytes for reading.
    • Finally, we print the result.

Please note that the nb_available function is typically used with stream-like objects, such as file streams or buffers.

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: