summaryrefslogtreecommitdiff
path: root/transcode.cpp
blob: 249ffb36db8ac854d0ac9df579fd51bead65f45b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "transcode.h"

Transcoder::Transcoder(std::istream& i, HTTPResponse& r, DecoderBase& d, EncoderBase& e) : is(i), res(r), decoder(d), encoder(e) {
}

void Transcoder::run() {
	char data[0x1000];
	bool encoding_fone = false;
	while(!encoding_fone) {
		size_t decoded_size = 0;
		char decoded_data[0x1000];
		if(is.good()) {
			is.read(data, 0x1000);
			decoded_size = decoder.decode((uint8_t*)data, is.gcount(), (uint8_t*)decoded_data, 0x1000);
		}
		char encoded_data[0x1000];
		size_t encoded_size = encoder.encode((uint8_t*)decoded_data, decoded_size, (uint8_t*)encoded_data, 0x1000);
		res.write(encoded_data, encoded_size);
	}
}