1 #ifndef __INKSCAPE_IO_BASE64STREAM_H__
2 #define __INKSCAPE_IO_BASE64STREAM_H__
4 /**
5 * Base64-enabled input and output streams
6 *
7 * This class allows easy encoding and decoding
8 * of Base64 data with a stream interface, hiding
9 * the implementation from the user.
10 *
11 * Authors:
12 * Bob Jamison <rjamison@titan.com>
13 *
14 * Copyright (C) 2004 Inkscape.org
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
20 #include "inkscapestream.h"
24 namespace Inkscape
25 {
26 namespace IO
27 {
29 //#########################################################################
30 //# B A S E 6 4 I N P U T S T R E A M
31 //#########################################################################
33 /**
34 * This class is for decoding a Base-64 encoded InputStream source
35 *
36 */
37 class Base64InputStream : public BasicInputStream
38 {
40 public:
42 Base64InputStream(InputStream &sourceStream);
44 virtual ~Base64InputStream();
46 virtual int available();
48 virtual void close();
50 virtual int get();
52 private:
54 int outBytes[3];
56 int outCount;
58 int padCount;
60 bool done;
62 }; // class Base64InputStream
67 //#########################################################################
68 //# B A S E 6 4 O U T P U T S T R E A M
69 //#########################################################################
71 /**
72 * This class is for Base-64 encoding data going to the
73 * destination OutputStream
74 *
75 */
76 class Base64OutputStream : public BasicOutputStream
77 {
79 public:
81 Base64OutputStream(OutputStream &destinationStream);
83 virtual ~Base64OutputStream();
85 virtual void close();
87 virtual void flush();
89 virtual void put(int ch);
91 /**
92 * Sets the maximum line length for base64 output. If
93 * set to <=0, then there will be no line breaks;
94 */
95 virtual void setColumnWidth(int val)
96 { columnWidth = val; }
98 private:
100 void putCh(int ch);
102 int column;
104 int columnWidth;
106 unsigned long outBuf;
108 int bitCount;
110 }; // class Base64OutputStream
118 } // namespace IO
119 } // namespace Inkscape
122 #endif /* __INKSCAPE_IO_BASE64STREAM_H__ */