CTPL Reference Manual: CtplOutputStream

## CtplOutputStream CtplOutputStream — CTPL's data output stream |

## Functions

CtplOutputStream * | ctpl_output_stream_new ()
CtplOutputStream * | ctpl_output_stream_ref ()
void | ctpl_output_stream_unref ()
GOutputStream * | ctpl_output_stream_get_stream ()
gboolean | ctpl_output_stream_write ()
gboolean | ctpl_output_stream_put_c ()

## Types and Values

| CtplOutputStream

## Includes

    #include <ctpl/ctpl.h>

## Description

The data output stream used by CTPL; built on top of GOutputStream.

A CtplOutputStream is created with `ctpl_output_stream_new()`. It uses a GObject-like refcounting, through `ctpl_output_stream_ref()` and `ctpl_output_stream_unref()`.

The errors that the functions in this module can throw comes from the `G_IO_ERROR` or `CTPL_IO_ERROR` domains unless otherwise mentioned.

## Functions

### ctpl_output_stream_new ()

    CtplOutputStream *
    ctpl_output_stream_new (GOutputStream *stream);

Creates a new CtplOutputStream for a given GOutputStream. This function adds a reference to the GOutputStream.

#### Parameters

stream | A GOutputStream |

#### Returns

A new CtplOutputStream.

Since 0.2

### ctpl_output_stream_ref ()

    CtplOutputStream *
    ctpl_output_stream_ref (CtplOutputStream *stream);

Adds a reference to a CtplOutputStream.

#### Parameters

stream | A CtplOutputStream |

#### Returns

The stream

Since 0.2

### ctpl_output_stream_unref ()

    void
    ctpl_output_stream_unref (CtplOutputStream *stream);

Removes a reference from a CtplOutputStream. When its reference count reaches 0, the stream is destroyed.

#### Parameters

stream | A CtplOutputStream |

Since 0.2

### ctpl_output_stream_get_stream ()

    GOutputStream *
    ctpl_output_stream_get_stream (CtplOutputStream *stream);

Gets the underlying GOutputStream associated with a CtplOutputStream.

#### Parameters

stream | A CtplOutputStream |

#### Returns

The underlying GOutputStream of `stream` .

[transfer none]

Since 0.3

### ctpl_output_stream_write ()

    gboolean
    ctpl_output_stream_write (CtplOutputStream *stream,
                              const gchar *data,
                              gssize length,
                              GError **error);

Writes a buffer to a CtplOutputStream.

#### Parameters

stream | A CtplOutputStream |
data | The data to write |
length | Length of the data in bytes, or -1 if it is a 0-terminated string |
error | Return location for errors, or `NULL` to ignore them |

#### Returns

`TRUE` on success, `FALSE` otherwise.

Since 0.2

### ctpl_output_stream_put_c ()

    gboolean
    ctpl_output_stream_put_c (CtplOutputStream *stream,
                              gchar c,
                              GError **error);

Writes a character to a CtplOutputStream.

#### Parameters

stream | A CtplOutputStream |
c | The character to write |
error | Return location for errors, or `NULL` to ignore them |

#### Returns

`TRUE` on success, `FALSE` otherwise.

Since 0.2

## Types and Values

### CtplOutputStream

    typedef struct _CtplOutputStream CtplOutputStream;

An opaque object representing an output data stream.