| 99 | } |
| 100 | |
| 101 | int ZipFile::Write(const void *data, size_t size) { |
| 102 | if (state == Inflate) { |
| 103 | inflateEnd(&z); |
| 104 | state = Initial; |
| 105 | } |
| 106 | if (state != Deflate) { |
| 107 | if (deflateInit(&z, 5) != Z_OK) |
| 108 | throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, "Failed to initialize zlib"); |
| 109 | state = Deflate; |
| 110 | } |
| 111 | |
| 112 | z.next_in = static_cast<unsigned char *>(const_cast<void *>(data)); |
| 113 | z.avail_in = size; |
| 114 | int ret = 0; |
| 115 | do { |
| 116 | z.avail_out = buffer.size(); |
| 117 | z.next_out = reinterpret_cast<Bytef*>(&buffer[0]); |
| 118 | ret = deflate(&z, size > 0 ? Z_NO_FLUSH : Z_FINISH); |
| 119 | uInt written = buffer.size() - z.avail_out; |
| 120 | if (written) { |
| 121 | if (is_file) |
| 122 | file.Write(&buffer[0], written); |
| 123 | else |
| 124 | index_buffer.insert(index_buffer.end(), &buffer[0], &buffer[written]); |
| 125 | } |
| 126 | } while (z.avail_out == 0); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | void ZipFile::Finish() { |
| 131 | while (Write(nullptr, 0) != Z_STREAM_END); |
nothing calls this directly
no test coverage detected