3 encode.h - c++ wrapper for a base64 encoding algorithm
5 This is part of the libb64 project, and has been placed in the public domain.
6 For details, see http://sourceforge.net/projects/libb64
8 #ifndef BASE64_ENCODE_H
9 #define BASE64_ENCODE_H
22 base64_encodestate _state;
25 encoder(int buffersize_in = BUFFERSIZE)
26 : _buffersize(buffersize_in)
29 int encode(char value_in)
31 return base64_encode_value(value_in);
34 int encode(const char* code_in, const int length_in, char* plaintext_out)
36 return base64_encode_block(code_in, length_in, plaintext_out, &_state);
39 int encode_end(char* plaintext_out)
41 return base64_encode_blockend(plaintext_out, &_state);
44 void encode(std::istream& istream_in, std::ostream& ostream_in)
46 base64_init_encodestate(&_state);
48 const int N = _buffersize;
49 char* plaintext = new char[N];
50 char* code = new char[2*N];
56 istream_in.read(plaintext, N);
57 plainlength = static_cast<int>(istream_in.gcount());
59 codelength = encode(plaintext, plainlength, code);
60 ostream_in.write(code, codelength);
62 while (istream_in.good() && plainlength > 0);
64 codelength = encode_end(code);
65 ostream_in.write(code, codelength);
67 base64_init_encodestate(&_state);
76 #endif // BASE64_ENCODE_H