Class: Gio::BufferedInputStream

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#availableInteger

Gets the size of the available data within the stream.

Returns:

  • (Integer)

    size of the available stream.

#buffer_sizeInteger

Returns buffer-size.

Returns:

  • (Integer)

    buffer-size

#buffer_size=(buffer_size) ⇒ Integer

Parameters:

  • buffer_size (Integer)

Returns:

  • (Integer)

    buffer-size

  • (Integer)

    buffer-size

#fill(count, cancellable) ⇒ Gio::gssize

Tries to read count bytes from the stream into the buffer. Will block during this read.

If count is zero, returns zero and does nothing. A value of count larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.

On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if count is zero), but never otherwise.

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

If cancellable is not nil, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

For the asynchronous, non-blocking, version of this function, see g_buffered_input_stream_fill_async().

Parameters:

  • count (Gio::gssize)

    the number of bytes that will be read from the stream

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::gssize)

    the number of bytes read into stream’s buffer, up to count, or -1 on error.

#fill_async(count, io_priority, cancellable, callback, user_data) ⇒ nil

Reads data into stream’s buffer asynchronously, up to count size. io_priority can be used to prioritize reads. For the synchronous version of this function, see g_buffered_input_stream_fill().

If count is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

Parameters:

  • count (Gio::gssize)

    the number of bytes that will be read from the stream

  • io_priority (Integer)

    the [I/O priority] of the request

  • cancellable (Gio::Cancellable)

    optional #GCancellable object

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback

  • user_data (GObject)

    a #gpointer

Returns:

  • (nil)

#fill_finish(result) ⇒ Gio::gssize

Finishes an asynchronous read.

Parameters:

Returns:

  • (Gio::gssize)

    a #gssize of the read stream, or ‘-1` on an error.

#new(base_stream) ⇒ Gio::InputStream

Creates a new GInput::Stream from the given base_stream, with a buffer set to the default size (4 kilobytes).

Parameters:

Returns:

#new_sized(base_stream, size) ⇒ Gio::InputStream

Creates a new GBuffered::InputStream from the given base_stream, with a buffer set to size.

Parameters:

  • base_stream (Gio::InputStream)

    a GInput::Stream

  • size (Integer)

    a #gsize

Returns:

#peek(buffer, offset, count) ⇒ Integer

Peeks in the buffer, copying data of size count into buffer, offset offset bytes.

Parameters:

  • buffer (Array<Integer>)

    a pointer to an allocated chunk of memory

  • offset (Integer)

    a #gsize

  • count (Integer)

    a #gsize

Returns:

  • (Integer)

    a #gsize of the number of bytes peeked, or -1 on error.

#peek_buffer(count) ⇒ Array<Integer>

Returns the buffer with the currently available bytes. The returned buffer must not be modified and will become invalid when reading from the stream or filling the buffer.

Parameters:

  • count (Integer)

    a #gsize to get the number of bytes available in the buffer

Returns:

  • (Array<Integer>)

    read-only buffer

#read_byte(cancellable) ⇒ Integer

Tries to read a single byte from the stream or the buffer. Will block during this read.

On success, the byte read from the stream is returned. On end of stream -1 is returned but it’s not an exceptional error and error is not set.

If cancellable is not nil, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Integer)

    the byte read from the stream, or -1 on end of stream or error.