summaryrefslogtreecommitdiffstats
path: root/src/io/gzipstream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/gzipstream.cpp')
-rw-r--r--src/io/gzipstream.cpp87
1 files changed, 43 insertions, 44 deletions
diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp
index 8db7155db..380c42411 100644
--- a/src/io/gzipstream.cpp
+++ b/src/io/gzipstream.cpp
@@ -71,11 +71,11 @@ GzipInputStream::~GzipInputStream()
{
close();
if ( srcBuf ) {
- free(srcBuf);
+ delete[] srcBuf;
srcBuf = NULL;
}
if ( outputBuf ) {
- free(outputBuf);
+ delete[] outputBuf;
outputBuf = NULL;
}
}
@@ -108,11 +108,11 @@ void GzipInputStream::close()
}
if ( srcBuf ) {
- free(srcBuf);
+ delete[] srcBuf;
srcBuf = NULL;
}
if ( outputBuf ) {
- free(outputBuf);
+ delete[] outputBuf;
outputBuf = NULL;
}
closed = true;
@@ -161,7 +161,7 @@ bool GzipInputStream::load()
int ch = source.get();
if (ch<0)
break;
- inputBuf.push_back((Byte)(ch & 0xff));
+ inputBuf.push_back(static_cast<Byte>(ch & 0xff));
}
long inputBufLen = inputBuf.size();
@@ -171,15 +171,15 @@ bool GzipInputStream::load()
}
srcLen = inputBuf.size();
- srcBuf = (Bytef *)malloc(srcLen * sizeof(Byte));
+ srcBuf = new Byte [srcLen];
if (!srcBuf) {
return false;
}
- outputBuf = (unsigned char *)malloc(OUT_SIZE);
+ outputBuf = new unsigned char [OUT_SIZE];
if ( !outputBuf ) {
- free(srcBuf);
- srcBuf = 0;
+ delete[] srcBuf;
+ srcBuf = NULL;
return false;
}
outputBufLen = 0; // Not filled in yet
@@ -187,33 +187,35 @@ bool GzipInputStream::load()
std::vector<unsigned char>::iterator iter;
Bytef *p = srcBuf;
for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter)
+ {
*p++ = *iter;
+ }
int headerLen = 10;
//Magic
- int val = (int)srcBuf[0];
- //printf("val:%x\n", val);
- val = (int)srcBuf[1];
- //printf("val:%x\n", val);
+ //int val = (int)srcBuf[0];
+ ////printf("val:%x\n", val);
+ //val = (int)srcBuf[1];
+ ////printf("val:%x\n", val);
- //Method
- val = (int)srcBuf[2];
- //printf("val:%x\n", val);
+ ////Method
+ //val = (int)srcBuf[2];
+ ////printf("val:%x\n", val);
//flags
- int flags = (int)srcBuf[3];
+ int flags = static_cast<int>(srcBuf[3]);
- //time
- val = (int)srcBuf[4];
- val = (int)srcBuf[5];
- val = (int)srcBuf[6];
- val = (int)srcBuf[7];
+ ////time
+ //val = (int)srcBuf[4];
+ //val = (int)srcBuf[5];
+ //val = (int)srcBuf[6];
+ //val = (int)srcBuf[7];
- //xflags
- val = (int)srcBuf[8];
- //OS
- val = (int)srcBuf[9];
+ ////xflags
+ //val = (int)srcBuf[8];
+ ////OS
+ //val = (int)srcBuf[9];
// if ( flags & FEXTRA ) {
// headerLen += 2;
@@ -272,19 +274,17 @@ bool GzipInputStream::load()
int GzipInputStream::fetchMore()
{
- int zerr = Z_OK;
-
// TODO assumes we aren't called till the buffer is empty
d_stream.next_out = outputBuf;
d_stream.avail_out = OUT_SIZE;
outputBufLen = 0;
outputBufPos = 0;
- zerr = inflate( &d_stream, Z_SYNC_FLUSH );
+ int zerr = inflate( &d_stream, Z_SYNC_FLUSH );
if ( zerr == Z_OK || zerr == Z_STREAM_END ) {
outputBufLen = OUT_SIZE - d_stream.avail_out;
if ( outputBufLen ) {
- crc = crc32(crc, (const Bytef *)outputBuf, outputBufLen);
+ crc = crc32(crc, const_cast<const Bytef *>(outputBuf), outputBufLen);
}
//printf("crc:%lx\n", crc);
// } else if ( zerr != Z_STREAM_END ) {
@@ -359,14 +359,14 @@ void GzipOutputStream::close()
uLong outlong = crc;
for (int n = 0; n < 4; n++)
{
- destination.put((int)(outlong & 0xff));
+ destination.put(static_cast<gunichar>(outlong & 0xff));
outlong >>= 8;
}
//# send the file length
outlong = totalIn & 0xffffffffL;
for (int n = 0; n < 4; n++)
{
- destination.put((int)(outlong & 0xff));
+ destination.put(static_cast<gunichar>(outlong & 0xff));
outlong >>= 8;
}
@@ -380,21 +380,23 @@ void GzipOutputStream::close()
*/
void GzipOutputStream::flush()
{
- if (closed || inputBuf.size()<1)
+ if (closed || inputBuf.empty())
+ {
return;
-
+ }
+
uLong srclen = inputBuf.size();
- Bytef *srcbuf = (Bytef *)malloc(srclen * sizeof(Byte));
+ Bytef *srcbuf = new Bytef [srclen];
if (!srcbuf)
{
return;
}
uLong destlen = srclen;
- Bytef *destbuf = (Bytef *)malloc((destlen + (srclen/100) + 13) * sizeof(Byte));
+ Bytef *destbuf = new Bytef [(destlen + (srclen/100) + 13)];
if (!destbuf)
{
- free(srcbuf);
+ delete[] srcbuf;
return;
}
@@ -403,9 +405,9 @@ void GzipOutputStream::flush()
for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter)
*p++ = *iter;
- crc = crc32(crc, (const Bytef *)srcbuf, srclen);
+ crc = crc32(crc, const_cast<const Bytef *>(srcbuf), srclen);
- int zerr = compress(destbuf, (uLongf *)&destlen, srcbuf, srclen);
+ int zerr = compress(destbuf, static_cast<uLongf *>(&destlen), srcbuf, srclen);
if (zerr != Z_OK)
{
printf("Some kind of problem\n");
@@ -421,11 +423,8 @@ void GzipOutputStream::flush()
destination.flush();
inputBuf.clear();
- free(srcbuf);
- free(destbuf);
-
- //printf("done\n");
-
+ delete[] srcbuf;
+ delete[] destbuf;
}