void ZipIODevice_FileEntry::deinit() { // Clean up decompression: switch (file_header.compression_method) { case zip_compress_store: // no compression break; case zip_compress_deflate: if (zstream_open) mz_inflateEnd(&zs); zstream_open = false; break; case zip_compress_shrunk: case zip_compress_expand_factor_1: case zip_compress_expand_factor_2: case zip_compress_expand_factor_3: case zip_compress_expand_factor_4: case zip_compress_implode: case zip_compress_tokenize: case zip_compress_deflate64: case zip_compress_pkware_implode: break; } }
~deflate_source() { if (compress) { while (drive(MZ_FINISH) == source_result::ok) { try_write_cur(); } } mz_inflateEnd(&str); }
DataBuffer ZLibCompression::decompress(const DataBuffer &data, bool raw) { const int window_bits = 15; DataBuffer zbuffer(1024*1024); IODevice_Memory output; mz_stream zs = { nullptr }; int result = mz_inflateInit2(&zs, raw ? -window_bits : window_bits); if (result != MZ_OK) throw Exception("Zlib inflateInit failed"); zs.next_in = (unsigned char *) data.get_data(); zs.avail_in = data.get_size(); // Continue feeding zlib data until we get our data: while (true) { zs.next_out = (unsigned char *) zbuffer.get_data(); zs.avail_out = zbuffer.get_size(); // Decompress data: int result = mz_inflate(&zs, 0); if (result == MZ_NEED_DICT) throw Exception("Zlib inflate wants a dictionary!"); if (result == MZ_DATA_ERROR) throw Exception("Zip data stream is corrupted"); if (result == MZ_STREAM_ERROR) throw Exception("Zip stream structure was inconsistent!"); if (result == MZ_MEM_ERROR) throw Exception("Zlib did not have enough memory to decompress file!"); if (result == MZ_BUF_ERROR) throw Exception("Not enough data in buffer when Z_FINISH was used"); if (result != MZ_OK && result != MZ_STREAM_END) throw Exception("Zlib inflate failed while decompressing zip file!"); output.write(zbuffer.get_data(), zbuffer.get_size() - zs.avail_out); if (result == MZ_STREAM_END) break; } mz_inflateEnd(&zs); return output.get_data(); }
bool ZipReader::read_local_file_header(bool allow_data_descriptor) { try { impl->local_header.load(impl->input); } catch (const Exception&) { return false; } if (has_data_descriptor() && !allow_data_descriptor) throw Exception("Zip file entry uses a data descriptor"); if ((impl->local_header.general_purpose_bit_flag & ZIP_ENCRYPTED) || (impl->local_header.general_purpose_bit_flag & ZIP_STRONG_ENCRYPTED)) throw Exception("Zip file entry is encrypted"); if (impl->zstream_open) mz_inflateEnd(&impl->zs); impl->zstream_open = false; if (impl->local_header.compression_method == zip_compress_deflate) { memset(&impl->zs, 0, sizeof(mz_stream)); int result = mz_inflateInit2(&impl->zs, -15); // Undocumented: if wbits is negative, zlib skips header check if (result != MZ_OK) throw Exception("Zlib inflateInit failed for zip index!"); impl->zstream_open = true; impl->compressed_pos = 0; } else if (impl->local_header.compression_method != zip_compress_store) { throw Exception("Zip file entry is compressed with an unsupported compression method"); } return true; }
void end_client_compressors() { free(decompression_buffer); if (inited) mz_inflateEnd(&stream); }
static int lmz_inflator_gc(lua_State* L) { lmz_stream_t* stream = luaL_checkudata(L, 1, "miniz_inflator"); mz_inflateEnd(&(stream->stream)); return 0; }
~ZipReader_Impl() { if (zstream_open) mz_inflateEnd(&zs); }
~deflate_source() { mz_inflateEnd(&str); }