Trait gio::prelude::InputStreamExt [−][src]
pub trait InputStreamExt: 'static {}Show methods
fn clear_pending(&self); fn close<P: IsA<Cancellable>>(
&self,
cancellable: Option<&P>
) -> Result<(), Error>; fn close_async<P: IsA<Cancellable>, Q: FnOnce(Result<(), Error>) + Send + 'static>(
&self,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn close_async_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>; fn has_pending(&self) -> bool; fn is_closed(&self) -> bool; fn read_bytes<P: IsA<Cancellable>>(
&self,
count: usize,
cancellable: Option<&P>
) -> Result<Bytes, Error>; fn read_bytes_async<P: IsA<Cancellable>, Q: FnOnce(Result<Bytes, Error>) + Send + 'static>(
&self,
count: usize,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn read_bytes_async_future(
&self,
count: usize,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<Bytes, Error>> + 'static>>; fn set_pending(&self) -> Result<(), Error>; fn skip<P: IsA<Cancellable>>(
&self,
count: usize,
cancellable: Option<&P>
) -> Result<isize, Error>; fn skip_async<P: IsA<Cancellable>, Q: FnOnce(Result<isize, Error>) + Send + 'static>(
&self,
count: usize,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn skip_async_future(
&self,
count: usize,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>;
Expand description
Trait containing all InputStream
methods.
Implementors
FileInputStream
, FilterInputStream
, InputStream
, MemoryInputStream
, PollableInputStream
, UnixInputStream
Required methods
fn clear_pending(&self)
fn clear_pending(&self)
Clears the pending flag on self
.
Closes the stream, releasing resources related to it.
Once the stream is closed, all other operations will return IOErrorEnum::Closed
.
Closing a stream multiple times will not return an error.
Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.
Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.
On failure the first error that happened will be reported, but the close
operation will finish as much as possible. A stream that failed to
close will still return IOErrorEnum::Closed
for all operations. Still, it
is important to check and report the error to the user.
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.
Cancelling a close will still leave the stream closed, but some streams
can use a faster close that doesn’t block to e.g. check errors.
cancellable
optional Cancellable
object, None
to ignore.
Returns
Requests an asynchronous closes of the stream, releasing resources related to it.
When the operation is finished callback
will be called.
You can then call g_input_stream_close_finish()
to get the result of the
operation.
For behaviour details see close()
.
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
callback
callback to call when the request is satisfied
fn close_async_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
fn has_pending(&self) -> bool
fn has_pending(&self) -> bool
fn read_bytes<P: IsA<Cancellable>>(
&self,
count: usize,
cancellable: Option<&P>
) -> Result<Bytes, Error>
fn read_bytes<P: IsA<Cancellable>>(
&self,
count: usize,
cancellable: Option<&P>
) -> Result<Bytes, Error>
Like InputStreamExtManual::read()
, this tries to read count
bytes from
the stream in a blocking fashion. However, rather than reading into
a user-supplied buffer, this will create a new glib::Bytes
containing
the data that was read. This may be easier to use from language
bindings.
If count is zero, returns a zero-length glib::Bytes
and does nothing. A
value of count
larger than G_MAXSSIZE
will cause a
IOErrorEnum::InvalidArgument
error.
On success, a new glib::Bytes
is returned. It is not an error if the
size of this object is not the same as the requested size, as it
can happen e.g. near the end of a file. A zero-length glib::Bytes
is
returned on end of file (or if count
is zero), but never
otherwise.
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 None
is returned and error
is set accordingly.
count
maximum number of bytes that will be read from the stream. Common values include 4096 and 8192.
cancellable
optional Cancellable
object, None
to ignore.
Returns
a new glib::Bytes
, or None
on error
Request an asynchronous read of count
bytes from the stream into a
new glib::Bytes
. When the operation is finished callback
will be
called. You can then call g_input_stream_read_bytes_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 new glib::Bytes
will be passed to the callback. It is
not an error if this is smaller than 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
.
count
the number of bytes that will be read from the stream
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
fn read_bytes_async_future(
&self,
count: usize,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<Bytes, Error>> + 'static>>
fn set_pending(&self) -> Result<(), Error>
fn set_pending(&self) -> Result<(), Error>
Tries to skip count
bytes from the stream. Will block during the operation.
This is identical to InputStreamExtManual::read()
, from a behaviour standpoint,
but the bytes that are skipped are not returned to the user. Some
streams have an implementation that is more efficient than reading the data.
This function is optional for inherited classes, as the default implementation emulates it using read.
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.
count
the number of bytes that will be skipped from the stream
cancellable
optional Cancellable
object, None
to ignore.
Returns
Number of bytes skipped, or -1 on error
Request an asynchronous skip of count
bytes from the stream.
When the operation is finished callback
will be called.
You can then call g_input_stream_skip_finish()
to get the result
of the operation.
During an async request no other sync and async calls are allowed,
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 skipped 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 skip
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.
count
the number of bytes that will be skipped from the stream
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