blob: 5244627dbecf315496d2425bd9b053054d532749 (
plain)
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
|
#include "transcode.h"
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>
Transcoder::Transcoder(std::string p, HTTPResponse& r, DecoderBase& d, EncoderBase& e) : path(p), res(r), decoder(d), encoder(e) {
}
void Transcoder::run() {
const std::streamsize buffer_size = 0x1000;
boost::iostreams::file_source is(path, std::ios::in | std::ios::binary);
boost::iostreams::filtering_istream s;
s.push(EncoderFilter(encoder), buffer_size);
s.push(DecoderFilter(decoder), buffer_size);
s.push(is, buffer_size);
char data[0x1000];
std::streamsize size = 1;
while(size) {
s.read(data, 0x1000);
size = s.gcount();
if(size > 0)
res.write(data, size);
}
}
|