2013-04-06 15:41:58 +00:00
|
|
|
#include "Base64Stream.h"
|
2012-11-29 09:50:40 +00:00
|
|
|
|
2012-11-29 10:16:05 +00:00
|
|
|
namespace pdf2htmlEX {
|
|
|
|
|
2012-11-29 11:38:57 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
2013-04-06 15:41:58 +00:00
|
|
|
ostream & Base64Stream::dumpto(ostream & out)
|
2012-11-29 11:38:57 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[3];
|
2013-02-25 13:08:47 +00:00
|
|
|
while(in->read((char*)buf, 3))
|
2012-11-29 11:38:57 +00:00
|
|
|
{
|
|
|
|
out << base64_encoding[(buf[0] & 0xfc)>>2]
|
|
|
|
<< base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)]
|
|
|
|
<< base64_encoding[((buf[1] & 0x0f)<<2) | ((buf[2] & 0xc0)>>6)]
|
|
|
|
<< base64_encoding[(buf[2] & 0x3f)];
|
|
|
|
}
|
2013-02-25 13:08:47 +00:00
|
|
|
auto cnt = in->gcount();
|
2012-11-29 11:38:57 +00:00
|
|
|
if(cnt > 0)
|
|
|
|
{
|
|
|
|
for(int i = cnt; i < 3; ++i)
|
|
|
|
buf[i] = 0;
|
|
|
|
|
|
|
|
out << base64_encoding[(buf[0] & 0xfc)>>2]
|
|
|
|
<< base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)];
|
|
|
|
|
|
|
|
if(cnt > 1)
|
|
|
|
{
|
|
|
|
out << base64_encoding[(buf[1] & 0x0f)<<2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << '=';
|
|
|
|
}
|
|
|
|
out << '=';
|
|
|
|
}
|
2012-11-29 10:16:05 +00:00
|
|
|
|
2012-11-29 11:38:57 +00:00
|
|
|
return out;
|
2012-11-29 10:16:05 +00:00
|
|
|
}
|
2012-11-29 11:38:57 +00:00
|
|
|
|
2013-04-06 15:41:58 +00:00
|
|
|
const char * Base64Stream::base64_encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
2012-11-29 11:38:57 +00:00
|
|
|
|
|
|
|
} //namespace pdf2htmlEX
|