MemoryOutputStream

GMemoryOutputStream is a class for using arbitrary memory chunks as output for GIO streaming output operations.

As of GLib 2.34, GMemoryOutputStream implements GPollableOutputStream.

Constructors

this
this(GMemoryOutputStream* gMemoryOutputStream)

Sets our main struct and passes it to the parent class

this
this(void* data, gsize size, GReallocFunc reallocFunction, GDestroyNotify destroyFunction)

Creates a new GMemoryOutputStream. If data is non-NULL, the stream will use that for its internal storage. If realloc_fn is non-NULL, it will be used for resizing the internal storage when necessary. To construct a fixed-size output stream, pass NULL as realloc_fn.

this
this()

Creates a new GMemoryOutputStream, using g_realloc() and g_free() for memory allocation. Since 2.36

Members

Functions

getData
void* getData()

Gets any loaded data from the ostream. Note that the returned pointer may become invalid on the next write or truncate operation on the stream.

getDataSize
gsize getDataSize()

Returns the number of bytes from the start up to including the last byte written in the stream that has not been truncated away. Since 2.18

getMemoryOutputStreamStruct
GMemoryOutputStream* getMemoryOutputStreamStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getSize
gsize getSize()

Gets the size of the currently allocated data area (available from g_memory_output_stream_get_data()). If the stream isn't growable (no realloc was passed to g_memory_output_stream_new()) then this is the maximum size of the stream and further writes will return G_IO_ERROR_NO_SPACE. Note that for growable streams the returned size may become invalid on the next write or truncate operation on the stream. If you want the number of bytes currently written to the stream, use g_memory_output_stream_get_data_size().

getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
stealAsBytes
GBytes* stealAsBytes()

Returns data from the ostream as a GBytes. ostream must be closed before calling this function. Since 2.34

stealData
void* stealData()

Gets any loaded data from the ostream. Ownership of the data is transferred to the caller; when no longer needed it must be freed using the free function set in ostream's "destroy-function" property. ostream must be closed before calling this function. Since 2.26

Mixins

__anonymous
mixin SeekableT!(GMemoryOutputStream)
Undocumented in source.

Variables

gMemoryOutputStream
GMemoryOutputStream* gMemoryOutputStream;

the main Gtk struct

Inherited Members

From OutputStream

gOutputStream
GOutputStream* gOutputStream;

the main Gtk struct

getOutputStreamStruct
GOutputStream* getOutputStreamStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
write
gssize write(void* buffer, gsize count, Cancellable cancellable)

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 G_IO_ERROR_INVALID_ARGUMENT 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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_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. Virtual: write_fn

writeAll
int writeAll(void* buffer, gsize count, gsize* bytesWritten, Cancellable cancellable)

Tries to write count bytes from buffer into the stream. Will block during the operation. This function is similar to g_output_stream_write(), 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 bytes_written is set to count. If there is an error during the operation FALSE is returned and error is set to indicate the error status, bytes_written is updated to contain the number of bytes written into the stream before the error occurred.

splice
gssize splice(InputStream source, GOutputStreamSpliceFlags flags, Cancellable cancellable)

Splices an input stream into an output stream.

flush
int flush(Cancellable cancellable)

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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned.

close
int close(Cancellable cancellable)

Closes the stream, releasing resources related to it. Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED. 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 G_IO_ERROR_CLOSED 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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED 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.

writeAsync
void writeAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

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 g_output_stream_write_finish() to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in G_IO_ERROR_PENDING errors. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT 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 G_IO_ERROR_WOULD_BLOCK - 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 G_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 g_output_stream_write().

writeFinish
gssize writeFinish(AsyncResultIF result)

Finishes a stream write operation.

spliceAsync
void spliceAsync(InputStream source, GOutputStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Splices a stream asynchronously. When the operation is finished callback will be called. You can then call g_output_stream_splice_finish() to get the result of the operation. For the synchronous, blocking version of this function, see g_output_stream_splice().

spliceFinish
gssize spliceFinish(AsyncResultIF result)

Finishes an asynchronous stream splice operation.

flushAsync
void flushAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Forces an asynchronous write of all user-space buffered data for the given stream. For behaviour details see g_output_stream_flush(). When the operation is finished callback will be called. You can then call g_output_stream_flush_finish() to get the result of the operation.

flushFinish
int flushFinish(AsyncResultIF result)

Finishes flushing an output stream.

closeAsync
void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

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 g_output_stream_close_finish() to get the result of the operation. For behaviour details see g_output_stream_close(). 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
int closeFinish(AsyncResultIF result)

Closes an output stream.

isClosing
int isClosing()

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

isClosed
int isClosed()

Checks if an output stream has already been closed.

hasPending
int hasPending()

Checks if an ouput stream has pending actions.

setPending
int setPending()

Sets stream to have actions pending. If the pending flag is already set or stream is closed, it will return FALSE and set error.

clearPending
void clearPending()

Clears the pending flag on stream.

writeBytes
gssize writeBytes(Bytes bytes, Cancellable cancellable)

Tries to write the data from bytes into the stream. Will block during the operation. If bytes is 0-length, returns 0 and does nothing. A GBytes larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT 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 the size of bytes is 0). If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_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.

writeBytesAsync
void writeBytesAsync(Bytes bytes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Request an asynchronous write of the data in bytes to the stream. When the operation is finished callback will be called. You can then call g_output_stream_write_bytes_finish() to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in G_IO_ERROR_PENDING errors. A GBytes larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT 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 G_IO_ERROR_WOULD_BLOCK - 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 G_PRIORITY_DEFAULT. For the synchronous, blocking version of this function, see g_output_stream_write_bytes().

writeBytesFinish
gssize writeBytesFinish(AsyncResultIF result)

Finishes a stream write-from-GBytes operation.

From SeekableIF

getSeekableTStruct
GSeekable* getSeekableTStruct()
Undocumented in source.
getStruct
void* getStruct()

the main Gtk struct as a void*

tell
long tell()

Tells the current position within the stream.

canSeek
int canSeek()

Tests if the stream supports the GSeekableIface.

seek
int seek(long offset, GSeekType type, Cancellable cancellable)

Seeks in the stream by the given offset, modified by type. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned.

canTruncate
int canTruncate()

Tests if the stream can be truncated.

truncate
int truncate(long offset, Cancellable cancellable)

Truncates a stream with a given offset. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. Virtual: truncate_fn

Meta