Add missing flush modes supported by zlib

pull/4381/head
Kim Kulling 2022-02-14 20:51:06 +01:00
parent 416f823866
commit 7c13b16d30
3 changed files with 17 additions and 6 deletions

View File

@ -188,7 +188,8 @@ XFileParser::XFileParser(const std::vector<char> &pBuffer) :
Compression compression; Compression compression;
uncompressed.resize(est_out + 1); uncompressed.resize(est_out + 1);
char *out = &uncompressed.front(); char *out = &uncompressed.front();
if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII, Compression::FlushMode::SyncFlush, -Compression::MAX_WBITS)) { if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII,
Compression::FlushMode::SyncFlush, -Compression::MaxWBits)) {
while (mP + 3 < mEnd) { while (mP + 3 < mEnd) {
uint16_t ofs = *((uint16_t *)mP); uint16_t ofs = *((uint16_t *)mP);
AI_SWAP2(ofs); AI_SWAP2(ofs);
@ -243,11 +244,11 @@ void XFileParser::ParseFile() {
} }
// parse specific object // parse specific object
if (objectName == "template") if (objectName == "template") {
ParseDataObjectTemplate(); ParseDataObjectTemplate();
else if (objectName == "Frame") } else if (objectName == "Frame") {
ParseDataObjectFrame(nullptr); ParseDataObjectFrame(nullptr);
else if (objectName == "Mesh") { } else if (objectName == "Mesh") {
// some meshes have no frames at all // some meshes have no frames at all
Mesh *mesh = new Mesh; Mesh *mesh = new Mesh;
ParseDataObjectMesh(mesh); ParseDataObjectMesh(mesh);
@ -286,11 +287,13 @@ void XFileParser::ParseDataObjectTemplate() {
while (running) { while (running) {
std::string s = GetNextToken(); std::string s = GetNextToken();
if (s == "}") if (s == "}") {
break; break;
}
if (s.length() == 0) if (s.length() == 0) {
ThrowException("Unexpected end of file reached while parsing template definition"); ThrowException("Unexpected end of file reached while parsing template definition");
}
} }
} }

View File

@ -104,6 +104,12 @@ static int getFlushMode(Compression::FlushMode flush) {
case Compression::FlushMode::NoFlush: case Compression::FlushMode::NoFlush:
z_flush = Z_NO_FLUSH; z_flush = Z_NO_FLUSH;
break; break;
case Compression::FlushMode::Block:
z_flush = Z_BLOCK;
break;
case Compression::FlushMode::Tree:
z_flush = Z_TREES;
break;
case Compression::FlushMode::SyncFlush: case Compression::FlushMode::SyncFlush:
z_flush = Z_SYNC_FLUSH; z_flush = Z_SYNC_FLUSH;
break; break;

View File

@ -70,6 +70,8 @@ public:
enum class FlushMode { enum class FlushMode {
InvalidFormat = -1, ///< Invalid enum type. InvalidFormat = -1, ///< Invalid enum type.
NoFlush = 0, ///< No flush, will be done on inflate end. NoFlush = 0, ///< No flush, will be done on inflate end.
Block, ///< Assists in combination of compress.
Tree, ///< Assists in combination of compress and returns if stream is finish.
SyncFlush, ///< Synced flush mode. SyncFlush, ///< Synced flush mode.
Finish, ///< Finish mode, all in once, no block access. Finish, ///< Finish mode, all in once, no block access.