CamelStream
3
CAMEL Library

# CamelStream

## Synopsis

    struct              CamelStream;
    ssize_t             camel_stream_read                   (CamelStream *stream,
                                                             char *buffer,
                                                             size_t n);
    ssize_t             camel_stream_write                  (CamelStream *stream,
                                                             const char *buffer,
                                                             size_t n);
    int                 camel_stream_flush                  (CamelStream *stream);
    int                 camel_stream_close                  (CamelStream *stream);
    gboolean            camel_stream_eos                    (CamelStream *stream);
    int                 camel_stream_reset                  (CamelStream *stream);
    ssize_t             camel_stream_write_string           (CamelStream *stream,
                                                             const char *string);
    ssize_t             camel_stream_printf                 (CamelStream *stream,
                                                             const char *fmt,
                                                             ...);
    ssize_t             camel_stream_vprintf                (CamelStream *stream,
                                                             const char *fmt,
                                                             va_list ap);
    ssize_t             camel_stream_write_to_stream        (CamelStream *stream,
                                                             CamelStream *output_stream);

## Description

## Details

### struct CamelStream

    struct CamelStream {
    	CamelObject parent_object;

    	gboolean eos;
    };

### camel_stream_read ()

    ssize_t             camel_stream_read                   (CamelStream *stream,
                                                             char *buffer,
                                                             size_t n);

Attempts to read up to `len` bytes from `stream` into `buf`.

`stream` :

  a CamelStream object.

`buffer` :

  output buffer

`n` :

  max number of bytes to read.

Returns :

  the number of bytes actually read, or `-1` on error and set errno.

### camel_stream_write ()

    ssize_t             camel_stream_write                  (CamelStream *stream,
                                                             const char *buffer,
                                                             size_t n);

Attempts to write up to `n` bytes of `buffer` into `stream`.

`stream` :

  a CamelStream object

`buffer` :

  buffer to write.

`n` :

  number of bytes to write

Returns :

  the number of bytes written to the stream, or `-1` on error along with setting errno.

### camel_stream_flush ()

    int                 camel_stream_flush                  (CamelStream *stream);

Flushes any buffered data to the stream's backing store. Only meaningful for writable streams.

`stream` :

  a CamelStream object

Returns :

  `0` on success or `-1` on fail along with setting errno.

### camel_stream_close ()

    int                 camel_stream_close                  (CamelStream *stream);

Closes the stream.

`stream` :

  a CamelStream object

Returns :

  `0` on success or `-1` on error.

### camel_stream_eos ()

    gboolean            camel_stream_eos                    (CamelStream *stream);

Tests if there are bytes left to read on the `stream` object.

`stream` :

  a CamelStream object

Returns :

  `TRUE` on EOS or `FALSE` otherwise.

### camel_stream_reset ()

    int                 camel_stream_reset                  (CamelStream *stream);

Resets the stream. That is, put it in a state where it can be read from the beginning again. Not all streams in Camel are seekable, but they must all be resettable.

`stream` :

  a CamelStream object

Returns :

  `0` on success or `-1` on error along with setting errno.

### camel_stream_write_string ()

    ssize_t             camel_stream_write_string           (CamelStream *stream,
                                                             const char *string);

Writes the string to the stream.

`stream` :

  a CamelStream object

`string` :

  a string

Returns :

  the number of characters written or `-1` on error.

### camel_stream_printf ()

    ssize_t             camel_stream_printf                 (CamelStream *stream,
                                                             const char *fmt,
                                                             ...);

Write formatted output to a stream.

`stream` :

  a CamelStream object

`fmt` :

  a printf-style format string

`...` :

Returns :

  the number of characters written or `-1` on error.

### camel_stream_vprintf ()

    ssize_t             camel_stream_vprintf                (CamelStream *stream,
                                                             const char *fmt,
                                                             va_list ap);

`stream` :

`fmt` :

`ap` :

Returns :

### camel_stream_write_to_stream ()

    ssize_t             camel_stream_write_to_stream        (CamelStream *stream,
                                                             CamelStream *output_stream);

Write all of a stream (until eos) into another stream, in a blocking fashion.

`stream` :

  source CamelStream object

`output_stream` :

  destination CamelStream object

Returns :

  `-1` on error, or the number of bytes succesfully copied across streams.