mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
COMMON: Add an optional argument to wrapCompressedReadStream, to simplify using streams that can't tell their size()
This commit is contained in:
parent
b6000da875
commit
b398dcabaf
@ -107,7 +107,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
GZipReadStream(SeekableReadStream *w) : _wrapped(w), _stream() {
|
||||
GZipReadStream(SeekableReadStream *w, uint32 knownSize = 0) : _wrapped(w), _stream() {
|
||||
assert(w != 0);
|
||||
|
||||
// Verify file header is correct
|
||||
@ -122,7 +122,8 @@ public:
|
||||
_origSize = w->readUint32LE();
|
||||
} else {
|
||||
// Original size not available in zlib format
|
||||
_origSize = 0;
|
||||
// use an otherwise known size if supplied.
|
||||
_origSize = knownSize;
|
||||
}
|
||||
_pos = 0;
|
||||
w->seek(0, SEEK_SET);
|
||||
@ -336,7 +337,7 @@ public:
|
||||
|
||||
#endif // USE_ZLIB
|
||||
|
||||
SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped) {
|
||||
SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, uint32 knownSize) {
|
||||
#if defined(USE_ZLIB)
|
||||
if (toBeWrapped) {
|
||||
uint16 header = toBeWrapped->readUint16BE();
|
||||
@ -345,7 +346,7 @@ SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped) {
|
||||
header % 31 == 0));
|
||||
toBeWrapped->seek(-2, SEEK_CUR);
|
||||
if (isCompressed)
|
||||
return new GZipReadStream(toBeWrapped);
|
||||
return new GZipReadStream(toBeWrapped, knownSize);
|
||||
}
|
||||
#endif
|
||||
return toBeWrapped;
|
||||
|
@ -86,10 +86,18 @@ bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen,
|
||||
* format. In the former case, the original stream is returned unmodified
|
||||
* (and in particular, not wrapped).
|
||||
*
|
||||
* Certain GZip-formats don't supply an easily readable length, if you
|
||||
* still need the length carried along with the stream, and you know
|
||||
* the decompressed length at wrap-time, then it can be supplied as knownSize
|
||||
* here. knownSize will be ignored if the GZip-stream DOES include a length.
|
||||
*
|
||||
* It is safe to call this with a NULL parameter (in this case, NULL is
|
||||
* returned).
|
||||
*
|
||||
* @param toBeWrapped the stream to be wrapped (if it is in gzip-format)
|
||||
* @param knownSize a supplied length of the compressed data (if not available directly)
|
||||
*/
|
||||
SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped);
|
||||
SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, uint32 knownSize = 0);
|
||||
|
||||
/**
|
||||
* Take an arbitrary WriteStream and wrap it in a custom stream which provides
|
||||
|
Loading…
x
Reference in New Issue
Block a user