zip end of file fixes

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4752 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2010-01-01 19:32:18 +00:00
parent 57c34a96ef
commit e2556f4956
+10 -3
View File
@@ -331,8 +331,9 @@ struct zipstream : stream
z_stream zfile;
uchar *buf;
int reading;
bool ended;
zipstream() : arch(NULL), info(NULL), buf(NULL), reading(-1)
zipstream() : arch(NULL), info(NULL), buf(NULL), reading(-1), ended(false)
{
zfile.zalloc = NULL;
zfile.zfree = NULL;
@@ -378,6 +379,7 @@ struct zipstream : stream
arch = a;
info = f;
reading = f->offset;
ended = false;
if(f->compressedsize) buf = new uchar[BUFSIZE];
return true;
}
@@ -400,7 +402,7 @@ struct zipstream : stream
}
long size() { return info->size; }
bool end() { return reading < 0; }
bool end() { return reading < 0 || ended; }
long tell() { return reading >= 0 ? (info->compressedsize ? zfile.total_out : reading - info->offset) : -1; }
bool seek(long pos, int whence)
@@ -420,6 +422,7 @@ struct zipstream : stream
if(fseek(arch->data, pos, SEEK_SET) < 0) return false;
arch->owner = this;
reading = pos;
ended = false;
return true;
}
@@ -438,6 +441,7 @@ struct zipstream : stream
zfile.avail_in = 0;
zfile.total_in = info->compressedsize;
arch->owner = NULL;
ended = false;
return true;
}
@@ -468,6 +472,7 @@ struct zipstream : stream
pos -= skipped;
}
ended = false;
return true;
}
@@ -485,6 +490,7 @@ struct zipstream : stream
int n = (int)fread(buf, 1, min(len, int(info->size + info->offset - reading)), arch->data);
reading += n;
if(n < len) ended = true;
return n;
}
@@ -496,7 +502,8 @@ struct zipstream : stream
int err = inflate(&zfile, Z_NO_FLUSH);
if(err != Z_OK)
{
if(err != Z_STREAM_END)
if(err == Z_STREAM_END) ended = true;
else
{
#ifndef STANDALONE
if(dbgzip) conoutf("inflate error: %s", err);