73 DataCompressionLayer::DataCompressionLayer()
87 compressor.zalloc = Z_NULL;
88 compressor.zfree = Z_NULL;
89 compressor.opaque = Z_NULL;
90 int ret = deflateInit(&compressor, -1);
96 DataCompressionLayer::DataCompressionLayer(z_stream customCompressor,
ProgressBar* _progMonitor)
105 progMonitor = _progMonitor;
106 compressor = customCompressor;
109 void DataCompressionLayer::writeInt(
int toWrite)
112 ByteUtilities::writeInt(inBuf + bufferIndex, toWrite);
116 void DataCompressionLayer::writeLong(uint64_t toWrite)
119 ByteUtilities::writeLong(inBuf + bufferIndex, toWrite);
123 void DataCompressionLayer::writeDouble(
double toWrite)
126 ByteUtilities::writeLong(inBuf + bufferIndex, ByteUtilities::convertDoubleToLong(toWrite));
130 void DataCompressionLayer::writeFile(FILE* toWrite)
132 while (!feof(toWrite))
135 assert(bufferIndex == 0);
142 void DataCompressionLayer::flush()
146 void DataCompressionLayer::makeRoom(
int count)
149 softFlush(Z_NO_FLUSH);
151 void DataCompressionLayer::softFlush(
int flushType)
158 compressor.avail_in = bufferIndex;
159 compressor.next_in = (
unsigned char*)inBuf;
162 compressor.avail_out = outBufferCurrentSize - posInCompBuffer;
163 assert(outBufferCurrentSize > posInCompBuffer);
164 DEBUGCOUT(2) <<
"Avail out: " << outBufferCurrentSize - posInCompBuffer<<endl;
165 compressor.next_out = outBuf + posInCompBuffer;
166 int ret = deflate(&compressor, flushType);
167 if (ret == Z_STREAM_ERROR)
168 cerr<<
"zlib stream error."<<endl;
170 posInCompBuffer = outBufferCurrentSize - compressor.avail_out;
171 if (posInCompBuffer == outBufferCurrentSize)
175 }
while (compressor.avail_out == 0);
176 assert(compressor.avail_in == 0);
181 void DataCompressionLayer::growOutputBuffer()
183 unsigned char* newBuffer =
new unsigned char[outBufferCurrentSize *
BUFFER_GROW_FACTOR];
184 copy(outBuf, outBuf + outBufferCurrentSize, newBuffer);
192 void DataCompressionLayer::pInc(
unsigned int count)
194 if (progMonitor !=
NULL)
195 progMonitor->incrementProgress(count);
198 unsigned char* DataCompressionLayer::getOutputBuffer()
202 int DataCompressionLayer::getOutputLength()
204 return posInCompBuffer;
206 DataCompressionLayer::~DataCompressionLayer()
208 deflateEnd(&compressor);
void copy(const char *dst,...)
#define BUFFER_GROW_FACTOR
size_t MONITOR_EXT_WRAP_NAME() fread(void *ptr, size_t size, size_t count, FILE *stream)
ssize_t MONITOR_EXT_WRAP_NAME() read(int fd, void *buf, size_t count)