gi-gio-2.0.24: Gio bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (inaki@blueleaf.cc)
Safe HaskellNone
LanguageHaskell2010

GI.Gio.Objects.OutputStream

Contents

Description

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.

Synopsis

Exported types

newtype OutputStream Source #

Memory-managed wrapper type.

Instances
GObject OutputStream Source # 
Instance details

Defined in GI.Gio.Objects.OutputStream

Methods

gobjectType :: IO GType #

HasParentTypes OutputStream Source # 
Instance details

Defined in GI.Gio.Objects.OutputStream

type ParentTypes OutputStream Source # 
Instance details

Defined in GI.Gio.Objects.OutputStream

type ParentTypes OutputStream = Object ': ([] :: [Type])

class (GObject o, IsDescendantOf OutputStream o) => IsOutputStream o Source #

Type class for types which can be safely cast to OutputStream, for instance with toOutputStream.

Instances
(GObject o, IsDescendantOf OutputStream o) => IsOutputStream o Source # 
Instance details

Defined in GI.Gio.Objects.OutputStream

toOutputStream :: (MonadIO m, IsOutputStream o) => o -> m OutputStream Source #

Cast to OutputStream, for types for which this is known to be safe. For general casts, use castTo.

Methods

clearPending

outputStreamClearPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a) 
=> a

stream: output stream

-> m () 

Clears the pending flag on stream.

close

outputStreamClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream.

-> Maybe b

cancellable: optional cancellable object

-> m ()

(Can throw GError)

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

outputStreamCloseAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream.

-> Int32

ioPriority: the io priority of the request.

-> Maybe b

cancellable: optional cancellable object

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> 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 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

outputStreamCloseFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a AsyncResult.

-> m ()

(Can throw GError)

Closes an output stream.

flush

outputStreamFlush Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> Maybe b

cancellable: optional cancellable object

-> m ()

(Can throw GError)

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

outputStreamFlushAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> Int32

ioPriority: the io priority of the request.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied

-> 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

outputStreamFlushFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a GAsyncResult.

-> m ()

(Can throw GError)

Finishes flushing an output stream.

hasPending

outputStreamHasPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a) 
=> a

stream: a OutputStream.

-> m Bool

Returns: True if stream has pending actions.

Checks if an output stream has pending actions.

isClosed

outputStreamIsClosed Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a) 
=> a

stream: a OutputStream.

-> m Bool

Returns: True if stream is closed. False otherwise.

Checks if an output stream has already been closed.

isClosing

outputStreamIsClosing Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a) 
=> a

stream: a OutputStream.

-> m Bool

Returns: True if stream is being closed. False otherwise.

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

outputStreamSetPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a) 
=> a

stream: a OutputStream.

-> m ()

(Can throw GError)

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

outputStreamSplice Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) 
=> a

stream: a OutputStream.

-> b

source: a InputStream.

-> [OutputStreamSpliceFlags]

flags: a set of OutputStreamSpliceFlags.

-> Maybe c

cancellable: optional Cancellable object, Nothing to ignore.

-> m Int64

Returns: a gssize containing the size of the data spliced, or -1 if an error occurred. Note that if the number of bytes spliced is greater than G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced. (Can throw GError)

Splices an input stream into an output stream.

spliceAsync

outputStreamSpliceAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsInputStream b, IsCancellable c) 
=> a

stream: a OutputStream.

-> b

source: a InputStream.

-> [OutputStreamSpliceFlags]

flags: a set of OutputStreamSpliceFlags.

-> Int32

ioPriority: the io priority of the request.

-> Maybe c

cancellable: optional Cancellable object, Nothing to ignore.

-> Maybe AsyncReadyCallback

callback: a 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

outputStreamSpliceFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a AsyncResult.

-> m Int64

Returns: a gssize of the number of bytes spliced. Note that if the number of bytes spliced is greater than G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced. (Can throw GError)

Finishes an asynchronous stream splice operation.

write

outputStreamWrite Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> ByteString

buffer: the buffer containing the data to write.

-> Maybe b

cancellable: optional cancellable object

-> m Int64

Returns: Number of bytes written, or -1 on error (Can throw GError)

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

outputStreamWriteAll Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> ByteString

buffer: the buffer containing the data to write.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> m Word64

(Can throw GError)

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

outputStreamWriteAllAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream

-> ByteString

buffer: the buffer containing the data to write

-> Int32

ioPriority: the io priority of the request

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> 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

outputStreamWriteAllFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream

-> b

result: a AsyncResult

-> m Word64

(Can throw GError)

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

outputStreamWriteAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream.

-> Maybe ByteString

buffer: the buffer containing the data to write.

-> Int32

ioPriority: the io priority of the request.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> 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 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.

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

outputStreamWriteBytes Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> Bytes

bytes: the Bytes to write

-> Maybe b

cancellable: optional cancellable object

-> m Int64

Returns: Number of bytes written, or -1 on error (Can throw GError)

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

outputStreamWriteBytesAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream.

-> Bytes

bytes: The bytes to write

-> Int32

ioPriority: the io priority of the request.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> 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

outputStreamWriteBytesFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a AsyncResult.

-> m Int64

Returns: a gssize containing the number of bytes written to the stream. (Can throw GError)

Finishes a stream write-from-Bytes operation.

writeFinish

outputStreamWriteFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a AsyncResult.

-> m Int64

Returns: a gssize containing the number of bytes written to the stream. (Can throw GError)

Finishes a stream write operation.

writev

outputStreamWritev Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> [OutputVector]

vectors: the buffer containing the GOutputVectors to write.

-> Maybe b

cancellable: optional cancellable object

-> m Word64

(Can throw GError)

Tries to write the bytes contained in the nVectors vectors into the stream. Will block during the operation.

If nVectors is 0 or the sum of all bytes in vectors is 0, returns 0 and does nothing.

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 nVectors is 0 or the sum of all bytes in vectors 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.

Some implementations of outputStreamWritev may have limitations on the aggregate buffer size, and will return IOErrorEnumInvalidArgument if these are exceeded. For example, when writing to a local file on UNIX platforms, the aggregate buffer size must not exceed G_MAXSSIZE bytes.

Since: 2.60

writevAll

outputStreamWritevAll Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: a OutputStream.

-> [OutputVector]

vectors: the buffer containing the GOutputVectors to write.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> m Word64

(Can throw GError)

Tries to write the bytes contained in the nVectors vectors into the stream. Will block during the operation.

This function is similar to outputStreamWritev, except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of all nVectors vectors, True is returned, and bytesWritten is set to the sum of all the sizes of vectors.

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.

The content of the individual elements of vectors might be changed by this function.

Since: 2.60

writevAllAsync

outputStreamWritevAllAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream

-> [OutputVector]

vectors: the buffer containing the GOutputVectors to write.

-> Int32

ioPriority: the I/O priority of the request

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> m () 

Request an asynchronous write of the bytes contained in the nVectors vectors into the stream. When the operation is finished callback will be called. You can then call outputStreamWritevAllFinish to get the result of the operation.

This is the asynchronous version of outputStreamWritevAll.

Call outputStreamWritevAllFinish 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 vectors will be made, so it must stay valid until callback is called. The content of the individual elements of vectors might be changed by this function.

Since: 2.60

writevAllFinish

outputStreamWritevAllFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream

-> b

result: a AsyncResult

-> m Word64

(Can throw GError)

Finishes an asynchronous stream write operation started with outputStreamWritevAllAsync.

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 outputStreamWritevAsync.

Since: 2.60

writevAsync

outputStreamWritevAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsCancellable b) 
=> a

stream: A OutputStream.

-> [OutputVector]

vectors: the buffer containing the GOutputVectors to write.

-> Int32

ioPriority: the I/O priority of the request.

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> Maybe AsyncReadyCallback

callback: callback to call when the request is satisfied

-> m () 

Request an asynchronous write of the bytes contained in nVectors vectors into the stream. When the operation is finished callback will be called. You can then call outputStreamWritevFinish 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.

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 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.

For the synchronous, blocking version of this function, see outputStreamWritev.

Note that no copy of vectors will be made, so it must stay valid until callback is called.

Since: 2.60

writevFinish

outputStreamWritevFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsOutputStream a, IsAsyncResult b) 
=> a

stream: a OutputStream.

-> b

result: a AsyncResult.

-> m Word64

(Can throw GError)

Finishes a stream writev operation.

Since: 2.60