GMimeStream

GMimeStream — Abstract stream class

Functions

Types and Values

Description

Streams are the fundamental method for reading and writing data used by GMime. You'll probably notice that the basic API is similar to that of the low-level Unix I/O layer (read(), write(), lseek(), etc) with some additional nicities such as a printf-like function.

Functions

g_mime_stream_construct ()

void
g_mime_stream_construct (GMimeStream *stream,
                         gint64 start,
                         gint64 end);

Initializes a new stream with bounds start and end .

Parameters

stream

a GMimeStream

 

start

start boundary

 

end

end boundary

 

g_mime_stream_read ()

ssize_t
g_mime_stream_read (GMimeStream *stream,
                    char *buf,
                    size_t len);

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

Parameters

stream

a GMimeStream

 

buf

buffer.

[array length=len][element-type guint8]

len

buffer length

 

Returns

the number of bytes read or -1 on fail.


g_mime_stream_write ()

ssize_t
g_mime_stream_write (GMimeStream *stream,
                     const char *buf,
                     size_t len);

Attempts to write up to len bytes of buf to stream .

Parameters

stream

a GMimeStream

 

buf

buffer.

[array length=len][element-type guint8]

len

buffer length

 

Returns

the number of bytes written or -1 on fail.


g_mime_stream_flush ()

int
g_mime_stream_flush (GMimeStream *stream);

Flushes output according to the backend's contract. This does not uniformly imply durable storage or flushing every underlying stream. In particular, GMimeStreamFilter completes its filters without flushing its source.

Parameters

stream

a GMimeStream

 

Returns

0 on success or -1 on fail.


g_mime_stream_seek ()

gint64
g_mime_stream_seek (GMimeStream *stream,
                    gint64 offset,
                    GMimeSeekWhence whence);

Repositions the offset of the stream stream to the argument offset according to the directive whence as follows:

GMIME_STREAM_SEEK_SET: Seek to offset using the backend's coordinate convention. Memory, block and file-backed streams use absolute backend coordinates, not offsets from bound_start. GMimeStreamNull uses offsets relative to bound_start.

GMIME_STREAM_SEEK_CUR: Seek offset bytes relative to the current offset of the stream.

GMIME_STREAM_SEEK_END: Seek offset bytes relative to the end of the stream (bound_end if non-negative).

Parameters

stream

a GMimeStream

 

offset

positional offset

 

whence

seek directive

 

Returns

the resultant position on success or -1 on fail.


g_mime_stream_tell ()

gint64
g_mime_stream_tell (GMimeStream *stream);

Gets the current offset within the stream.

Parameters

stream

a GMimeStream

 

Returns

the current position within the stream or -1 on fail.


g_mime_stream_reset ()

int
g_mime_stream_reset (GMimeStream *stream);

Resets the stream.

Parameters

stream

a GMimeStream

 

Returns

0 on success or -1 on fail.


g_mime_stream_eos ()

gboolean
g_mime_stream_eos (GMimeStream *stream);

Tests the end-of-stream indicator for stream .

Parameters

stream

a GMimeStream

 

Returns

TRUE on EOS or FALSE otherwise.


g_mime_stream_close ()

int
g_mime_stream_close (GMimeStream *stream);

Closes the stream according to the backend's ownership policy. This does not release the caller's object reference and is not equivalent to g_object_unref(). Retaining an object reference does not protect a shared resource from an explicit close.

Flush buffered output explicitly and check errors before closing. GMimeStreamBuffer and GMimeStreamCat release their source references without explicitly closing them; GMimeStreamBuffer discards any unflushed output. GMimeStreamFilter completes writes and closes its source only when its owner flag is enabled. Finalization cannot report I/O failures. A failed close may already have released the backend resource.

Parameters

stream

a GMimeStream

 

Returns

0 on success or -1 on fail.


g_mime_stream_length ()

gint64
g_mime_stream_length (GMimeStream *stream);

Gets the length of the stream.

Parameters

stream

a GMimeStream

 

Returns

the length of the stream or -1 if unknown.


g_mime_stream_substream ()

GMimeStream *
g_mime_stream_substream (GMimeStream *stream,
                         gint64 start,
                         gint64 end);

Creates a new view of stream without moving its logical position. Bounds use absolute backend coordinates, not offsets relative to the parent's start. An unbounded end inherits a finite parent end, so a nested view cannot escape its parent's range. Empty ranges are permitted.

The view retains its parent. Backend-specific lifetime rules still apply; retaining the parent is not in itself protection against explicitly closing its backend.

Parameters

stream

a GMimeStream

 

start

absolute start boundary within stream 's bounds

 

end

absolute end boundary, or -1 for the parent's end

 

Returns

a substream, or NULL on failure. Invalid ranges fail with errno set to EINVAL before invoking the backend.

[transfer full][nullable]


g_mime_stream_set_bounds ()

void
g_mime_stream_set_bounds (GMimeStream *stream,
                          gint64 start,
                          gint64 end);

Set the bounds on a stream.

Parameters

stream

a GMimeStream

 

start

start boundary

 

end

end boundary

 

g_mime_stream_get_bounds ()

void
g_mime_stream_get_bounds (GMimeStream *stream,
                          gint64 *start,
                          gint64 *end);

Gets the stream's bounds without invoking any virtual methods.

Parameters

stream

a GMimeStream

 

start

absolute start boundary.

[out][optional]

end

absolute end boundary, or -1 if unbounded.

[out][optional]

g_mime_stream_get_position ()

gint64
g_mime_stream_get_position (GMimeStream *stream);

Gets the base class's logical position without calling the tell virtual method. Intended for stream implementations; applications should normally use g_mime_stream_tell().

Parameters

stream

a GMimeStream

 

Returns

the stored absolute position.


g_mime_stream_set_position ()

void
g_mime_stream_set_position (GMimeStream *stream,
                            gint64 position);

Updates the base class's logical position after a subclass performs I/O. This does not seek the backend, change bounds, or call any virtual methods. Applications should use g_mime_stream_seek() to reposition a stream.

Parameters

stream

a GMimeStream

 

position

nonnegative absolute position

 

g_mime_stream_write_string ()

ssize_t
g_mime_stream_write_string (GMimeStream *stream,
                            const char *str);

Writes string to stream .

Parameters

stream

a GMimeStream

 

str

string to write

 

Returns

the number of bytes written or -1 on fail.


g_mime_stream_printf ()

ssize_t
g_mime_stream_printf (GMimeStream *stream,
                      const char *fmt,
                      ...);

Write formatted output to a stream.

Parameters

stream

a GMimeStream

 

fmt

format

 

...

arguments

 

Returns

the number of bytes written or -1 on fail.


g_mime_stream_write_to_stream ()

gint64
g_mime_stream_write_to_stream (GMimeStream *src,
                               GMimeStream *dest);

Attempts to write the source stream to the destination stream.

Parameters

src

source stream

 

dest

destination stream

 

Returns

the number of bytes written or -1 on fail.


g_mime_stream_writev ()

gint64
g_mime_stream_writev (GMimeStream *stream,
                      GMimeStreamIOVector *vector,
                      size_t count);

Writes at most count blocks described by vector to stream .

Parameters

stream

a GMimeStream

 

vector

a GMimeStreamIOVector.

[array length=count]

count

number of vector elements

 

Returns

the number of bytes written or -1 on fail.

Types and Values

enum GMimeSeekWhence

Relative seek position.

Members

GMIME_STREAM_SEEK_SET

Seek relative to the beginning of the stream.

 

GMIME_STREAM_SEEK_CUR

Seek relative to the current position in the stream.

 

GMIME_STREAM_SEEK_END

Seek relative to the end of the stream.

 

GMimeStreamIOVector

typedef struct {
	void *data;
	size_t len;
} GMimeStreamIOVector;

An I/O vector for use with g_mime_stream_writev().

Members

void *data;

data to pass to the I/O function.

 

size_t len;

length of the data, in bytes.

 

GMimeStream

typedef struct _GMimeStream GMimeStream;

Abstract I/O stream class.