mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Allow seeking a ZStream back to 0 (but no other location)
This commit is contained in:
parent
1c6f4c29c4
commit
6f8fd916f3
@ -170,6 +170,59 @@ close_write() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements seeking within the stream. ZStreamBuf only allows seeking back
|
||||
* to the beginning of the stream.
|
||||
*/
|
||||
streampos ZStreamBuf::
|
||||
seekoff(streamoff off, ios_seekdir dir, ios_openmode which) {
|
||||
// Necessary for tellg() to work after seeking to 0.
|
||||
if (dir == ios::cur && off == 0) {
|
||||
if (_source->tellg() == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (off != 0 || dir != ios::beg) {
|
||||
// We only know how to reposition to the beginning.
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (which != ios::in) {
|
||||
// We can only do this with the input stream.
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t n = egptr() - gptr();
|
||||
gbump(n);
|
||||
|
||||
_source->seekg(0, ios::beg);
|
||||
if (_source->tellg() == 0) {
|
||||
_z_source.next_in = Z_NULL;
|
||||
_z_source.avail_in = 0;
|
||||
_z_source.next_out = Z_NULL;
|
||||
_z_source.avail_out = 0;
|
||||
int result = inflateReset(&_z_source);
|
||||
if (result < 0) {
|
||||
show_zlib_error("inflateReset", result, _z_source);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements seeking within the stream. ZStreamBuf only allows seeking back
|
||||
* to the beginning of the stream.
|
||||
*/
|
||||
streampos ZStreamBuf::
|
||||
seekpos(streampos pos, ios_openmode which) {
|
||||
return seekoff(pos, ios::beg, which);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the system ostream implementation when its internal buffer is
|
||||
* filled, plus one character.
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
void open_write(ostream *dest, bool owns_dest, int compression_level);
|
||||
void close_write();
|
||||
|
||||
virtual streampos seekoff(streamoff off, ios_seekdir dir, ios_openmode which);
|
||||
virtual streampos seekpos(streampos pos, ios_openmode which);
|
||||
|
||||
protected:
|
||||
virtual int overflow(int c);
|
||||
virtual int sync();
|
||||
|
Loading…
x
Reference in New Issue
Block a user