1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<refentry id="gmime-streams">
<refmeta>
<refentrytitle>GMime Streams</refentrytitle>
<refmiscinfo>GMime Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GMime Streams</refname>
<refpurpose>How to use GMime Streams</refpurpose>
</refnamediv>
<refsect1 id="stream-overview">
<title>Overview of Streams</title>
<para>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.</para>
<para>The three (3) basic stream types are: GMimeStreamFile,
GMimeStreamFs and GMimeStreamMem. You can manipulate all three
streams using the GMimeStream interfaces. In addition, some of
these streams have extended interfaces to allow more fine grained
manipulation.</para>
<para>GMimeStreamFile and GMimeStreamFs are very similar in that
they are both meant for reading and writing data to the file
system (in the form of files). Since GMimeStreamFile is an
abstracted layer above the standard libc FILE type, one of the
added benefits is buffered I/O. GMimeStreamFs, on the other hand,
is an abstracted layer above Unix file descriptors. While a
GMimeStreamFs can be used on top of a UNIX socket or pipe, you
must be careful because sockets and pipes are not seekable.</para>
<para>Unlike the previous 2 stream types, GMimeStreamMem does not
interact with the file system at all (except maybe the swap
partition/file indirectly). Memory streams are handy when you want
reads and writes to be nearly instantaneous and/or if you don't
want to create a temporary file on disk.</para>
<para>The four (4) advanced stream types are GMimeStreamMmap,
GMimeStreamNull, GMimeStreamBuffer and GMimeStreamFilter.</para>
<para>Our most simple stream, GMimeStreamNull, is the stream
equivalent of /dev/null on Unix systems. The main difference is
that GMimeStreamNull records the number of bytes written to it -
you may find this useful if you need to know the number of bytes a
GMimeObject (for example) will require.</para>
<para>GMimeStreamMmap is a memory-mapped stream. This isn't
guarenteed to work on all systems since not all systems support
the POSIX mmap system call, but for those that do - this might
present a faster stream than GMimeStreamFs and/or
GMimeStreamFile. You'll have to do some experimentation to know
for sure.</para>
<para>The GMimeStreamBuffer can be used on top of any other type
of stream and has 3 modes: block reads, block writes, and cached
reads. Block reads are especially useful if you will be making a
lot of small reads from a stream that accesses the file
system. Block writes are useful for very much the same reason. The
final mode, cached reads, can become memory intensive but can be
very helpful when inheriting from a stream that does not support
seeking (Note: this mode is the least tested so be careful using
it).</para>
<para>Our final stream type, GMimeStreamFilter, can also be used
on top of another stream. This stream, as you may have guessed,
filters reads and writes to its inherited stream. For example, one
could write a compression filter and apply it to a
GMimeStreamFilter and any further reads or writes would be
(un)compressed.</para>
</refsect1>
</refentry>
|