Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
InputStream
has functions to read from a stream (inputStreamRead
),
to close a stream (inputStreamClose
) and to skip some content
(inputStreamSkip
).
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use outputStreamSplice
.
See the documentation for IOStream
for details of thread safety of
streaming APIs.
All of these functions have async variants too.
Synopsis
- newtype InputStream = InputStream (ManagedPtr InputStream)
- class (GObject o, IsDescendantOf InputStream o) => IsInputStream o
- toInputStream :: (MonadIO m, IsInputStream o) => o -> m InputStream
- inputStreamClearPending :: (HasCallStack, MonadIO m, IsInputStream a) => a -> m ()
- inputStreamClose :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Maybe b -> m ()
- inputStreamCloseAsync :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- inputStreamCloseFinish :: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) => a -> b -> m ()
- inputStreamHasPending :: (HasCallStack, MonadIO m, IsInputStream a) => a -> m Bool
- inputStreamIsClosed :: (HasCallStack, MonadIO m, IsInputStream a) => a -> m Bool
- inputStreamRead :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> ByteString -> Maybe b -> m (Int64, ByteString)
- inputStreamReadAll :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> ByteString -> Maybe b -> m (ByteString, Word64)
- inputStreamReadAllAsync :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ByteString
- inputStreamReadAllFinish :: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) => a -> b -> m Word64
- inputStreamReadAsync :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Maybe ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m (Maybe ByteString)
- inputStreamReadBytes :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Word64 -> Maybe b -> m Bytes
- inputStreamReadBytesAsync :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Word64 -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- inputStreamReadBytesFinish :: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) => a -> b -> m Bytes
- inputStreamReadFinish :: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) => a -> b -> m Int64
- inputStreamSetPending :: (HasCallStack, MonadIO m, IsInputStream a) => a -> m ()
- inputStreamSkip :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Word64 -> Maybe b -> m Int64
- inputStreamSkipAsync :: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) => a -> Word64 -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- inputStreamSkipFinish :: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) => a -> b -> m Int64
Exported types
newtype InputStream Source #
Memory-managed wrapper type.
Instances
Eq InputStream Source # | |
Defined in GI.Gio.Objects.InputStream (==) :: InputStream -> InputStream -> Bool # (/=) :: InputStream -> InputStream -> Bool # | |
GObject InputStream Source # | |
Defined in GI.Gio.Objects.InputStream | |
ManagedPtrNewtype InputStream Source # | |
Defined in GI.Gio.Objects.InputStream | |
TypedObject InputStream Source # | |
Defined in GI.Gio.Objects.InputStream | |
HasParentTypes InputStream Source # | |
Defined in GI.Gio.Objects.InputStream | |
IsGValue (Maybe InputStream) Source # | Convert |
Defined in GI.Gio.Objects.InputStream gvalueGType_ :: IO GType # gvalueSet_ :: Ptr GValue -> Maybe InputStream -> IO () # gvalueGet_ :: Ptr GValue -> IO (Maybe InputStream) # | |
type ParentTypes InputStream Source # | |
Defined in GI.Gio.Objects.InputStream |
class (GObject o, IsDescendantOf InputStream o) => IsInputStream o Source #
Type class for types which can be safely cast to InputStream
, for instance with toInputStream
.
Instances
(GObject o, IsDescendantOf InputStream o) => IsInputStream o Source # | |
Defined in GI.Gio.Objects.InputStream |
toInputStream :: (MonadIO m, IsInputStream o) => o -> m InputStream Source #
Cast to InputStream
, for types for which this is known to be safe. For general casts, use castTo
.
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, clearPending, close, closeAsync, closeFinish, forceFloating, freezeNotify, getv, hasPending, isClosed, isFloating, notify, notifyByPspec, read, readAll, readAllAsync, readAllFinish, readAsync, readBytes, readBytesAsync, readBytesFinish, readFinish, ref, refSink, runDispose, skip, skipAsync, skipFinish, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getData, getProperty, getQdata.
Setters
clearPending
inputStreamClearPending Source #
:: (HasCallStack, MonadIO m, IsInputStream a) | |
=> a |
|
-> m () |
Clears the pending flag on stream
.
close
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m () | (Can throw |
Closes the stream, releasing resources related to it.
Once the stream is closed, all other operations will return IOErrorEnumClosed
.
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 IOErrorEnumClosed
for all operations. Still, it
is important to check and report the error to the user.
If cancellable
is not Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
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.
closeAsync
inputStreamCloseAsync Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
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 inputStreamCloseFinish
to get the result of the
operation.
For behaviour details see inputStreamClose
.
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.
closeFinish
inputStreamCloseFinish Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m () | (Can throw |
Finishes closing a stream asynchronously, started from inputStreamCloseAsync
.
hasPending
inputStreamHasPending Source #
:: (HasCallStack, MonadIO m, IsInputStream a) | |
=> a |
|
-> m Bool | Returns: |
Checks if an input stream has pending actions.
isClosed
:: (HasCallStack, MonadIO m, IsInputStream a) | |
=> a |
|
-> m Bool | Returns: |
Checks if an input stream is closed.
read
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Maybe b |
|
-> m (Int64, ByteString) | Returns: Number of bytes read, or -1 on error, or 0 on end of file. (Can throw |
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 IOErrorEnumInvalidArgument
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 Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
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.
readAll
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Maybe b |
|
-> m (ByteString, Word64) | (Can throw |
Tries to read count
bytes from the stream into the buffer starting at
buffer
. Will block during this read.
This function is similar to inputStreamRead
, 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 bytesRead
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 GError
, if this function returns False
(and sets error
) then
bytesRead
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 inputStreamRead
.
readAllAsync
inputStreamReadAllAsync Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m ByteString |
Request an asynchronous read of count
bytes from the stream into the
buffer starting at buffer
.
This is the asynchronous equivalent of inputStreamReadAll
.
Call inputStreamReadAllFinish
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 PRIORITY_DEFAULT
.
Since: 2.44
readAllFinish
inputStreamReadAllFinish Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Word64 | (Can throw |
Finishes an asynchronous stream read operation started with
inputStreamReadAllAsync
.
As a special exception to the normal conventions for functions that
use GError
, if this function returns False
(and sets error
) then
bytesRead
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 inputStreamReadAsync
.
Since: 2.44
readAsync
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Maybe ByteString |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m (Maybe ByteString) |
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 inputStreamReadFinish
to get the result of the
operation.
During an async request no other sync and async calls are allowed on stream
, and will
result in IOErrorEnumPending
errors.
A value of count
larger than G_MAXSSIZE
will cause a IOErrorEnumInvalidArgument
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 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.
readBytes
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Word64 |
|
-> Maybe b |
|
-> m Bytes | Returns: a new |
Like inputStreamRead
, 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 Bytes
containing
the data that was read. This may be easier to use from language
bindings.
If count is zero, returns a zero-length Bytes
and does nothing. A
value of count
larger than G_MAXSSIZE
will cause a
IOErrorEnumInvalidArgument
error.
On success, a new 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 Bytes
is
returned on end of file (or if count
is zero), but never
otherwise.
If cancellable
is not Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
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 Nothing
is returned and error
is set accordingly.
Since: 2.34
readBytesAsync
inputStreamReadBytesAsync Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Word64 |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Request an asynchronous read of count
bytes from the stream into a
new Bytes
. When the operation is finished callback
will be
called. You can then call inputStreamReadBytesFinish
to get the
result of the operation.
During an async request no other sync and async calls are allowed
on stream
, and will result in IOErrorEnumPending
errors.
A value of count
larger than G_MAXSSIZE
will cause a
IOErrorEnumInvalidArgument
error.
On success, the new 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 PRIORITY_DEFAULT
.
Since: 2.34
readBytesFinish
inputStreamReadBytesFinish Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Bytes | Returns: the newly-allocated |
Finishes an asynchronous stream read-into-tBytes
operation.
Since: 2.34
readFinish
inputStreamReadFinish Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Int64 | Returns: number of bytes read in, or -1 on error, or 0 on end of file. (Can throw |
Finishes an asynchronous stream read operation.
setPending
inputStreamSetPending Source #
:: (HasCallStack, MonadIO m, IsInputStream a) | |
=> a |
|
-> m () | (Can throw |
Sets stream
to have actions pending. If the pending flag is
already set or stream
is closed, it will return False
and set
error
.
skip
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Word64 |
|
-> Maybe b |
|
-> m Int64 | Returns: Number of bytes skipped, or -1 on error (Can throw |
Tries to skip count
bytes from the stream. Will block during the operation.
This is identical to inputStreamRead
, 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 Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
will be returned. If an
operation was partially finished when the operation was cancelled the
partial result will be returned, without an error.
skipAsync
:: (HasCallStack, MonadIO m, IsInputStream a, IsCancellable b) | |
=> a |
|
-> Word64 |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Request an asynchronous skip of count
bytes from the stream.
When the operation is finished callback
will be called.
You can then call inputStreamSkipFinish
to get the result
of the operation.
During an async request no other sync and async calls are allowed,
and will result in IOErrorEnumPending
errors.
A value of count
larger than G_MAXSSIZE
will cause a IOErrorEnumInvalidArgument
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 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.
skipFinish
inputStreamSkipFinish Source #
:: (HasCallStack, MonadIO m, IsInputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Int64 | Returns: the size of the bytes skipped, or |
Finishes a stream skip operation.