Trait gio::prelude::InputStreamExtManual
source · pub trait InputStreamExtManual: Sized {
// Required methods
fn read<B: AsMut<[u8]>, C: IsA<Cancellable>>(
&self,
buffer: B,
cancellable: Option<&C>
) -> Result<usize, Error>;
fn read_all<B: AsMut<[u8]>, C: IsA<Cancellable>>(
&self,
buffer: B,
cancellable: Option<&C>
) -> Result<(usize, Option<Error>), Error>;
fn read_all_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize, Option<Error>), (B, Error)>) + 'static, C: IsA<Cancellable>>(
&self,
buffer: B,
io_priority: Priority,
cancellable: Option<&C>,
callback: Q
);
fn read_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize), (B, Error)>) + 'static, C: IsA<Cancellable>>(
&self,
buffer: B,
io_priority: Priority,
cancellable: Option<&C>,
callback: Q
);
fn read_all_future<B: AsMut<[u8]> + Send + 'static>(
&self,
buffer: B,
io_priority: Priority
) -> Pin<Box<dyn Future<Output = Result<(B, usize, Option<Error>), (B, Error)>> + 'static>>;
fn read_future<B: AsMut<[u8]> + Send + 'static>(
&self,
buffer: B,
io_priority: Priority
) -> Pin<Box<dyn Future<Output = Result<(B, usize), (B, Error)>> + 'static>>;
// Provided methods
fn into_read(self) -> InputStreamRead<Self> ⓘ
where Self: IsA<InputStream> { ... }
fn into_async_buf_read(
self,
buffer_size: usize
) -> InputStreamAsyncBufRead<Self>
where Self: IsA<InputStream> { ... }
}Required Methods§
sourcefn read<B: AsMut<[u8]>, C: IsA<Cancellable>>(
&self,
buffer: B,
cancellable: Option<&C>
) -> Result<usize, Error>
fn read<B: AsMut<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, cancellable: Option<&C> ) -> Result<usize, Error>
Tries to read count bytes from the stream into the buffer starting at
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 IOErrorEnum::InvalidArgument 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.
The returned buffer is not a nul-terminated string, it can contain nul bytes
at any position, and this function doesn’t nul-terminate the buffer.
If cancellable is not None, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 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.
cancellable
optional Cancellable object, None to ignore.
Returns
Number of bytes read, or -1 on error, or 0 on end of file.
buffer
a buffer to read data into (which should be at least count bytes long).
sourcefn read_all<B: AsMut<[u8]>, C: IsA<Cancellable>>(
&self,
buffer: B,
cancellable: Option<&C>
) -> Result<(usize, Option<Error>), Error>
fn read_all<B: AsMut<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, cancellable: Option<&C> ) -> Result<(usize, Option<Error>), Error>
Tries to read count bytes from the stream into the buffer starting at
buffer. Will block during this read.
This function is similar to InputStreamExtManual::read(), except it tries to
read as many bytes as requested, only stopping on an error or end of stream.
On a successful read of count bytes, or if we reached the end of the
stream, true is returned, and bytes_read is set to the number of bytes
read into buffer.
If there is an error during the operation false is returned and error
is set to indicate the error status.
As a special exception to the normal conventions for functions that
use glib::Error, if this function returns false (and sets error) then
bytes_read will be set to the number of bytes that were successfully
read before the error was encountered. This functionality is only
available from C. If you need it from another language then you must
write your own loop around InputStreamExtManual::read().
cancellable
optional Cancellable object, None to ignore.
Returns
true on success, false if there was an error
buffer
a buffer to read data into (which should be at least count bytes long).
bytes_read
location to store the number of bytes that was read from the stream
sourcefn read_all_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize, Option<Error>), (B, Error)>) + 'static, C: IsA<Cancellable>>(
&self,
buffer: B,
io_priority: Priority,
cancellable: Option<&C>,
callback: Q
)
fn read_all_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize, Option<Error>), (B, Error)>) + 'static, C: IsA<Cancellable>>( &self, buffer: B, io_priority: Priority, cancellable: Option<&C>, callback: Q )
Request an asynchronous read of count bytes from the stream into the
buffer starting at buffer.
This is the asynchronous equivalent of InputStreamExtManual::read_all().
Call g_input_stream_read_all_finish() to collect the result.
Any outstanding I/O request with higher priority (lower numerical
value) will be executed before an outstanding request with lower
priority. Default priority is G_PRIORITY_DEFAULT.
io_priority
the [I/O priority][io-priority] of the request
cancellable
optional Cancellable object, None to ignore
callback
callback to call when the request is satisfied
Returns
buffer
a buffer to read data into (which should be at least count bytes long)
sourcefn read_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize), (B, Error)>) + 'static, C: IsA<Cancellable>>(
&self,
buffer: B,
io_priority: Priority,
cancellable: Option<&C>,
callback: Q
)
fn read_async<B: AsMut<[u8]> + Send + 'static, Q: FnOnce(Result<(B, usize), (B, Error)>) + 'static, C: IsA<Cancellable>>( &self, buffer: B, io_priority: Priority, cancellable: Option<&C>, callback: Q )
Request an asynchronous read of count bytes from the stream into the buffer
starting at buffer. When the operation is finished callback will be called.
You can then call g_input_stream_read_finish() to get the result of the
operation.
During an async request no other sync and async calls are allowed on self, and will
result in IOErrorEnum::Pending errors.
A value of count larger than G_MAXSSIZE will cause a IOErrorEnum::InvalidArgument error.
On success, the number of bytes read into the buffer will be passed to the
callback. 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, but generally we try to read
as many bytes as requested. Zero is returned on end of file
(or if count is zero), but never otherwise.
Any outstanding i/o request with higher priority (lower numerical value) will
be executed before an outstanding request with lower priority. Default
priority is G_PRIORITY_DEFAULT.
The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.
io_priority
the [I/O priority][io-priority] of the request.
cancellable
optional Cancellable object, None to ignore.
callback
callback to call when the request is satisfied
Returns
buffer
a buffer to read data into (which should be at least count bytes long).