MCPcopy Create free account
hub / github.com/assimp/assimp / decompress

Method decompress

code/Common/Compression.cpp:133–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131static constexpr size_t MYBLOCK = 32786;
132
133size_t Compression::decompress(const void *data, size_t in, std::vector<char> &uncompressed) {
134 ai_assert(mImpl != nullptr);
135 if (data == nullptr || in == 0) {
136 return 0l;
137 }
138
139 mImpl->mZSstream.next_in = (Bytef*)(data);
140 mImpl->mZSstream.avail_in = (uInt)in;
141
142 int ret = 0;
143 size_t total = 0l;
144 const int flushMode = getFlushMode(mImpl->mFlushMode);
145 if (flushMode == Z_FINISH) {
146 mImpl->mZSstream.avail_out = static_cast<uInt>(uncompressed.size());
147 mImpl->mZSstream.next_out = reinterpret_cast<Bytef *>(&*uncompressed.begin());
148 ret = inflate(&mImpl->mZSstream, Z_FINISH);
149
150 if (ret != Z_STREAM_END && ret != Z_OK) {
151 throw DeadlyImportError("Compression", "Failure decompressing this file using gzip.");
152 }
153 total = mImpl->mZSstream.avail_out;
154 } else {
155 do {
156 Bytef block[MYBLOCK] = {};
157 mImpl->mZSstream.avail_out = MYBLOCK;
158 mImpl->mZSstream.next_out = block;
159
160 ret = inflate(&mImpl->mZSstream, flushMode);
161
162 if (ret != Z_STREAM_END && ret != Z_OK) {
163 throw DeadlyImportError("Compression", "Failure decompressing this file using gzip.");
164 }
165 const size_t have = MYBLOCK - mImpl->mZSstream.avail_out;
166 total += have;
167 uncompressed.resize(total);
168 ::memcpy(uncompressed.data() + total - have, block, have);
169 } while (ret != Z_STREAM_END);
170 }
171
172 return total;
173}
174
175size_t Compression::decompressBlock(const void *data, size_t in, char *out, size_t availableOut) {
176 ai_assert(mImpl != nullptr);

Callers 3

ReadBinaryDataArrayFunction · 0.80
ParseMagicTokenMethod · 0.80
InternReadFileMethod · 0.80

Calls 6

getFlushModeFunction · 0.85
DeadlyImportErrorFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected