Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
OutputStream
has functions to write to a stream (outputStreamWrite
),
to close a stream (outputStreamClose
) and to flush pending writes
(outputStreamFlush
).
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.
- newtype OutputStream = OutputStream (ManagedPtr OutputStream)
- class GObject o => IsOutputStream o
- toOutputStream :: IsOutputStream o => o -> IO OutputStream
- noOutputStream :: Maybe OutputStream
- data OutputStreamClearPendingMethodInfo
- outputStreamClearPending :: (HasCallStack, MonadIO m, IsOutputStream a) => a -> m ()
- data OutputStreamCloseMethodInfo
- outputStreamClose :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Maybe b -> m ()
- data OutputStreamCloseAsyncMethodInfo
- outputStreamCloseAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamCloseFinishMethodInfo
- outputStreamCloseFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m ()
- data OutputStreamFlushMethodInfo
- outputStreamFlush :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Maybe b -> m ()
- data OutputStreamFlushAsyncMethodInfo
- outputStreamFlushAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamFlushFinishMethodInfo
- outputStreamFlushFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m ()
- data OutputStreamHasPendingMethodInfo
- outputStreamHasPending :: (HasCallStack, MonadIO m, IsOutputStream a) => a -> m Bool
- data OutputStreamIsClosedMethodInfo
- outputStreamIsClosed :: (HasCallStack, MonadIO m, IsOutputStream a) => a -> m Bool
- data OutputStreamIsClosingMethodInfo
- outputStreamIsClosing :: (HasCallStack, MonadIO m, IsOutputStream a) => a -> m Bool
- data OutputStreamSetPendingMethodInfo
- outputStreamSetPending :: (HasCallStack, MonadIO m, IsOutputStream a) => a -> m ()
- data OutputStreamSpliceMethodInfo
- outputStreamSplice :: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) => a -> b -> [OutputStreamSpliceFlags] -> Maybe c -> m Int64
- data OutputStreamSpliceAsyncMethodInfo
- outputStreamSpliceAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) => a -> b -> [OutputStreamSpliceFlags] -> Int32 -> Maybe c -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamSpliceFinishMethodInfo
- outputStreamSpliceFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m Int64
- data OutputStreamWriteMethodInfo
- outputStreamWrite :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> ByteString -> Maybe b -> m Int64
- data OutputStreamWriteAllMethodInfo
- outputStreamWriteAll :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> ByteString -> Maybe b -> m Word64
- data OutputStreamWriteAllAsyncMethodInfo
- outputStreamWriteAllAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamWriteAllFinishMethodInfo
- outputStreamWriteAllFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m Word64
- data OutputStreamWriteAsyncMethodInfo
- outputStreamWriteAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Maybe ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamWriteBytesMethodInfo
- outputStreamWriteBytes :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Bytes -> Maybe b -> m Int64
- data OutputStreamWriteBytesAsyncMethodInfo
- outputStreamWriteBytesAsync :: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) => a -> Bytes -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data OutputStreamWriteBytesFinishMethodInfo
- outputStreamWriteBytesFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m Int64
- data OutputStreamWriteFinishMethodInfo
- outputStreamWriteFinish :: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) => a -> b -> m Int64
Exported types
newtype OutputStream Source #
GObject OutputStream Source # | |
IsObject OutputStream Source # | |
IsOutputStream OutputStream Source # | |
((~) * info (ResolveOutputStreamMethod t OutputStream), MethodInfo * info OutputStream p) => IsLabel t (OutputStream -> p) Source # | |
((~) * info (ResolveOutputStreamMethod t OutputStream), MethodInfo * info OutputStream p) => IsLabelProxy t (OutputStream -> p) Source # | |
HasAttributeList * OutputStream Source # | |
type AttributeList OutputStream Source # | |
type SignalList OutputStream Source # | |
class GObject o => IsOutputStream o Source #
toOutputStream :: IsOutputStream o => o -> IO OutputStream Source #
Methods
clearPending
data OutputStreamClearPendingMethodInfo Source #
((~) * signature (m ()), MonadIO m, IsOutputStream a) => MethodInfo * OutputStreamClearPendingMethodInfo a signature Source # | |
outputStreamClearPending Source #
:: (HasCallStack, MonadIO m, IsOutputStream a) | |
=> a |
|
-> m () |
Clears the pending flag on stream
.
close
data OutputStreamCloseMethodInfo Source #
((~) * signature (Maybe b -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamCloseMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream 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.
Closing a stream will automatically flush any outstanding buffers in the stream.
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, otherwise
there might be a loss of data as all data might not be written.
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 there some streams
can use a faster close that doesn't block to e.g. check errors. On
cancellation (as with any error) there is no guarantee that all written
data will reach the target.
closeAsync
data OutputStreamCloseAsyncMethodInfo Source #
((~) * signature (Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamCloseAsyncMethodInfo a signature Source # | |
outputStreamCloseAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Requests an asynchronous close of the stream, releasing resources
related to it. When the operation is finished callback
will be
called. You can then call outputStreamCloseFinish
to get
the result of the operation.
For behaviour details see outputStreamClose
.
The asyncronous 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
data OutputStreamCloseFinishMethodInfo Source #
((~) * signature (b -> m ()), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamCloseFinishMethodInfo a signature Source # | |
outputStreamCloseFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m () | (Can throw |
Closes an output stream.
flush
data OutputStreamFlushMethodInfo Source #
((~) * signature (Maybe b -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamFlushMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m () | (Can throw |
Forces a write of all user-space buffered data for the given
stream
. Will block during the operation. Closing the stream will
implicitly cause a flush.
This function is optional for inherited classes.
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.
flushAsync
data OutputStreamFlushAsyncMethodInfo Source #
((~) * signature (Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamFlushAsyncMethodInfo a signature Source # | |
outputStreamFlushAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Forces an asynchronous write of all user-space buffered data for
the given stream
.
For behaviour details see outputStreamFlush
.
When the operation is finished callback
will be
called. You can then call outputStreamFlushFinish
to get the
result of the operation.
flushFinish
data OutputStreamFlushFinishMethodInfo Source #
((~) * signature (b -> m ()), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamFlushFinishMethodInfo a signature Source # | |
outputStreamFlushFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m () | (Can throw |
Finishes flushing an output stream.
hasPending
data OutputStreamHasPendingMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsOutputStream a) => MethodInfo * OutputStreamHasPendingMethodInfo a signature Source # | |
outputStreamHasPending Source #
:: (HasCallStack, MonadIO m, IsOutputStream a) | |
=> a |
|
-> m Bool | Returns: |
Checks if an ouput stream has pending actions.
isClosed
data OutputStreamIsClosedMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsOutputStream a) => MethodInfo * OutputStreamIsClosedMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream a) | |
=> a |
|
-> m Bool |
Checks if an output stream has already been closed.
isClosing
data OutputStreamIsClosingMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsOutputStream a) => MethodInfo * OutputStreamIsClosingMethodInfo a signature Source # | |
outputStreamIsClosing Source #
:: (HasCallStack, MonadIO m, IsOutputStream a) | |
=> a |
|
-> m Bool |
Checks if an output stream is being closed. This can be used inside e.g. a flush implementation to see if the flush (or other i/o operation) is called from within the closing operation.
Since: 2.24
setPending
data OutputStreamSetPendingMethodInfo Source #
((~) * signature (m ()), MonadIO m, IsOutputStream a) => MethodInfo * OutputStreamSetPendingMethodInfo a signature Source # | |
outputStreamSetPending Source #
:: (HasCallStack, MonadIO m, IsOutputStream 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
.
splice
data OutputStreamSpliceMethodInfo Source #
((~) * signature (b -> [OutputStreamSpliceFlags] -> Maybe c -> m Int64), MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) => MethodInfo * OutputStreamSpliceMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) | |
=> a |
|
-> b |
|
-> [OutputStreamSpliceFlags] |
|
-> Maybe c |
|
-> m Int64 | Returns: a |
Splices an input stream into an output stream.
spliceAsync
data OutputStreamSpliceAsyncMethodInfo Source #
((~) * signature (b -> [OutputStreamSpliceFlags] -> Int32 -> Maybe c -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) => MethodInfo * OutputStreamSpliceAsyncMethodInfo a signature Source # | |
outputStreamSpliceAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) | |
=> a |
|
-> b |
|
-> [OutputStreamSpliceFlags] |
|
-> Int32 |
|
-> Maybe c |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Splices a stream asynchronously.
When the operation is finished callback
will be called.
You can then call outputStreamSpliceFinish
to get the
result of the operation.
For the synchronous, blocking version of this function, see
outputStreamSplice
.
spliceFinish
data OutputStreamSpliceFinishMethodInfo Source #
((~) * signature (b -> m Int64), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamSpliceFinishMethodInfo a signature Source # | |
outputStreamSpliceFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Int64 | Returns: a |
Finishes an asynchronous stream splice operation.
write
data OutputStreamWriteMethodInfo Source #
((~) * signature (ByteString -> Maybe b -> m Int64), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Maybe b |
|
-> m Int64 | Returns: Number of bytes written, or -1 on error (Can throw |
Tries to write count
bytes from buffer
into the stream. Will block
during the operation.
If count is 0, returns 0 and does nothing. A value of count
larger than G_MAXSSIZE
will cause a IOErrorEnumInvalidArgument
error.
On success, the number of bytes written to the stream is returned.
It is not an error if this is not the same as the requested size, as it
can happen e.g. on a partial I/O error, or if there is not enough
storage in the stream. All writes block until at least one byte
is written or an error occurs; 0 is never returned (unless
count
is 0).
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.
writeAll
data OutputStreamWriteAllMethodInfo Source #
((~) * signature (ByteString -> Maybe b -> m Word64), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteAllMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Maybe b |
|
-> m Word64 | (Can throw |
Tries to write count
bytes from buffer
into the stream. Will block
during the operation.
This function is similar to outputStreamWrite
, except it tries to
write as many bytes as requested, only stopping on an error.
On a successful write of count
bytes, True
is returned, and bytesWritten
is set to count
.
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
bytesWritten
will be set to the number of bytes that were
successfully written 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
outputStreamWrite
.
writeAllAsync
data OutputStreamWriteAllAsyncMethodInfo Source #
((~) * signature (ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteAllAsyncMethodInfo a signature Source # | |
outputStreamWriteAllAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> ByteString |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Request an asynchronous write of count
bytes from buffer
into
the stream. When the operation is finished callback
will be called.
You can then call outputStreamWriteAllFinish
to get the result of the
operation.
This is the asynchronous version of outputStreamWriteAll
.
Call outputStreamWriteAllFinish
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
.
Note that no copy of buffer
will be made, so it must stay valid
until callback
is called.
Since: 2.44
writeAllFinish
data OutputStreamWriteAllFinishMethodInfo Source #
((~) * signature (b -> m Word64), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamWriteAllFinishMethodInfo a signature Source # | |
outputStreamWriteAllFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Word64 | (Can throw |
Finishes an asynchronous stream write operation started with
outputStreamWriteAllAsync
.
As a special exception to the normal conventions for functions that
use GError
, if this function returns False
(and sets error
) then
bytesWritten
will be set to the number of bytes that were
successfully written 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
outputStreamWriteAsync
.
Since: 2.44
writeAsync
data OutputStreamWriteAsyncMethodInfo Source #
((~) * signature (Maybe ByteString -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteAsyncMethodInfo a signature Source # | |
outputStreamWriteAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Maybe ByteString |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Request an asynchronous write of count
bytes from buffer
into
the stream. When the operation is finished callback
will be called.
You can then call outputStreamWriteFinish
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 written 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. on a partial I/O error,
but generally we try to write as many bytes as requested.
You are guaranteed that this method will never fail with
IOErrorEnumWouldBlock
- if stream
can't accept more data, the
method will just wait until this changes.
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 asyncronous 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.
For the synchronous, blocking version of this function, see
outputStreamWrite
.
Note that no copy of buffer
will be made, so it must stay valid
until callback
is called. See outputStreamWriteBytesAsync
for a Bytes
version that will automatically hold a reference to
the contents (without copying) for the duration of the call.
writeBytes
data OutputStreamWriteBytesMethodInfo Source #
((~) * signature (Bytes -> Maybe b -> m Int64), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteBytesMethodInfo a signature Source # | |
outputStreamWriteBytes Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Bytes |
|
-> Maybe b |
|
-> m Int64 | Returns: Number of bytes written, or -1 on error (Can throw |
A wrapper function for outputStreamWrite
which takes a
Bytes
as input. This can be more convenient for use by language
bindings or in other cases where the refcounted nature of Bytes
is helpful over a bare pointer interface.
However, note that this function may still perform partial writes,
just like outputStreamWrite
. If that occurs, to continue
writing, you will need to create a new Bytes
containing just the
remaining bytes, using bytesNewFromBytes
. Passing the same
Bytes
instance multiple times potentially can result in duplicated
data in the output stream.
writeBytesAsync
data OutputStreamWriteBytesAsyncMethodInfo Source #
((~) * signature (Bytes -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsOutputStream a, IsCancellable b) => MethodInfo * OutputStreamWriteBytesAsyncMethodInfo a signature Source # | |
outputStreamWriteBytesAsync Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) | |
=> a |
|
-> Bytes |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
This function is similar to outputStreamWriteAsync
, but
takes a Bytes
as input. Due to the refcounted nature of Bytes
,
this allows the stream to avoid taking a copy of the data.
However, note that this function may still perform partial writes,
just like outputStreamWriteAsync
. If that occurs, to continue
writing, you will need to create a new Bytes
containing just the
remaining bytes, using bytesNewFromBytes
. Passing the same
Bytes
instance multiple times potentially can result in duplicated
data in the output stream.
For the synchronous, blocking version of this function, see
outputStreamWriteBytes
.
writeBytesFinish
data OutputStreamWriteBytesFinishMethodInfo Source #
((~) * signature (b -> m Int64), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamWriteBytesFinishMethodInfo a signature Source # | |
outputStreamWriteBytesFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Int64 | Returns: a |
Finishes a stream write-from-Bytes
operation.
writeFinish
data OutputStreamWriteFinishMethodInfo Source #
((~) * signature (b -> m Int64), MonadIO m, IsOutputStream a, IsAsyncResult b) => MethodInfo * OutputStreamWriteFinishMethodInfo a signature Source # | |
outputStreamWriteFinish Source #
:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m Int64 | Returns: a |
Finishes a stream write operation.