1.5 <GBufferedInputStream>

Class: <GBufferedInputStream>

It derives from <GFilterInputStream>.

Buffered input stream implements <GFilterInputStream> and provides for buffered reads.

By default, <GBufferedInputStream>’s buffer size is set at 4 kilobytes.

To create a buffered input stream, use buffered-input-stream:new, or buffered-input-stream:new-sized to specify the buffer’s size at construction.

To get the size of a buffer within a buffered input stream, use buffered-input-stream:get-buffer-size. To change the size of a buffered input stream’s buffer, use buffered-input-stream:set-buffer-size. Note that the buffer’s size cannot be reduced below the size of the data within the buffer.

Fields

parent-instance

Properties

Property: buffered-input-stream:buffer-size self

The size of the backend buffer, in bytes.

Its value is an unsigned 32-bit integer.

Set it with (set! (buffered-input-stream:buffer-size self) value).

Procedures

Method: buffered-input-stream:fill self count [cancellable] ⇒ %return
Method: fill self count [cancellable] ⇒ %return

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 Gio.IOErrorEnum.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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.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 buffered-input-stream:fill-async.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

count

Passed: a 64-bit integer.

the number of bytes that will be read from the stream

cancellable

Passed, or left out: a <GCancellable>, or #f.

optional <GCancellable> object, NULL to ignore

%return

Returned: a 64-bit integer.

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

Method: buffered-input-stream:fill-async self count io-priority [cancellable] [callback]
Method: fill-async self count io-priority [cancellable] [callback]

Reads data into self’s buffer asynchronously, up to count size. io-priority can be used to prioritize reads. For the synchronous version of this function, see 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.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

count

Passed: a 64-bit integer.

the number of bytes that will be read from the stream

io-priority

Passed: a 32-bit integer.

the I/O priority of the request

cancellable

Passed, or left out: a <GCancellable>, or #f.

optional <GCancellable> object

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

a gpointer

Method: buffered-input-stream:fill-finish self result ⇒ %return
Method: fill-finish self result ⇒ %return

Finishes an asynchronous read.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a 64-bit integer.

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

Method: buffered-input-stream:get-available self ⇒ %return
Method: get-available self ⇒ %return

Gets the size of the available data within the stream.

self

Passed: a <GBufferedInputStream>.

<GBufferedInputStream>

%return

Returned: an unsigned 64-bit integer.

size of the available stream.

Method: buffered-input-stream:get-buffer-size self ⇒ %return
Method: get-buffer-size self ⇒ %return

Gets the size of the input buffer.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

%return

Returned: an unsigned 64-bit integer.

the current buffer size.

Procedure: buffered-input-stream:new base-stream ⇒ %return

Creates a new <GInputStream> from the given base-stream, with a buffer set to the default size (4 kilobytes).

base-stream

Passed: a <GInputStream>.

a <GInputStream>

%return

Returned: a <GInputStream>.

a <GInputStream> for the given base-stream.

Procedure: buffered-input-stream:new-sized base-stream size ⇒ %return

Creates a new <GBufferedInputStream> from the given base-stream, with a buffer set to size.

base-stream

Passed: a <GInputStream>.

a <GInputStream>

size

Passed: an unsigned 64-bit integer.

a gsize

%return

Returned: a <GInputStream>.

a <GInputStream>.

Method: buffered-input-stream:peek self buffer offset ⇒ %return
Method: peek self buffer offset ⇒ %return

Peeks in the buffered input, copying count bytes of data from offset bytes in the buffered input into buffer.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

a pointer to an allocated chunk of memory, which must be at least count bytes long

offset

Passed: an unsigned 64-bit integer.

offset into the buffered input to peek from, or zero to peek from the next byte in the buffered input onwards

%return

Returned: an unsigned 64-bit integer.

the number of bytes copied, which may be zero

count

Not passed: guile-gi gives the length of buffer.

number of bytes to peek

Method: buffered-input-stream:peek-buffer self ⇒ %return
Method: peek-buffer self ⇒ %return

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.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

%return

Returned: a bytevector.

read-only buffer

count

Not returned: it is the length of %return.

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

Method: buffered-input-stream:read-byte self [cancellable] ⇒ %return
Method: read-byte self [cancellable] ⇒ %return

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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.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.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

cancellable

Passed, or left out: a <GCancellable>, or #f.

optional <GCancellable> object, NULL to ignore

%return

Returned: a 32-bit integer.

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

Method: buffered-input-stream:set-buffer-size self size
Method: set-buffer-size self size

Sets the size of the internal buffer of self to size, or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

size

Passed: an unsigned 64-bit integer.

a gsize

Virtual methods

Virtual method: buffered-input-stream:do-fill implementor self count [cancellable] ⇒ %return

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 Gio.IOErrorEnum.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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.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 buffered-input-stream:fill-async.

To override it in a new class, give register-type #:vfuncs `((fill . ,procedure)). The procedure is called as (procedure self count cancellable) ⇒ %return.

implementor

Passed: the class whose implementation to call: <GBufferedInputStream>, or a class that derives from it, or its GType number.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

count

Passed: a 64-bit integer.

the number of bytes that will be read from the stream

cancellable

Passed, or left out: a <GCancellable>, or #f.

optional <GCancellable> object, NULL to ignore

%return

Returned: a 64-bit integer.

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

Virtual method: buffered-input-stream:do-fill-async implementor self count io-priority [cancellable] [callback]

Reads data into self’s buffer asynchronously, up to count size. io-priority can be used to prioritize reads. For the synchronous version of this function, see 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.

To override it in a new class, give register-type #:vfuncs `((fill-async . ,procedure)). The procedure is called as (procedure self count io-priority cancellable callback user-data).

implementor

Passed: the class whose implementation to call: <GBufferedInputStream>, or a class that derives from it, or its GType number.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

count

Passed: a 64-bit integer.

the number of bytes that will be read from the stream

io-priority

Passed: a 32-bit integer.

the I/O priority of the request

cancellable

Passed, or left out: a <GCancellable>, or #f.

optional <GCancellable> object

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

a gpointer

Virtual method: buffered-input-stream:do-fill-finish implementor self result ⇒ %return

Finishes an asynchronous read.

To override it in a new class, give register-type #:vfuncs `((fill-finish . ,procedure)). The procedure is called as (procedure self result) ⇒ %return.

implementor

Passed: the class whose implementation to call: <GBufferedInputStream>, or a class that derives from it, or its GType number.

self

Passed: a <GBufferedInputStream>.

a <GBufferedInputStream>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a 64-bit integer.

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