| 101 | } |
| 102 | |
| 103 | static bool zlibToCompressed(const byte* bytes, uLongf length, DataBuf& result) { |
| 104 | uLongf compressedLen = length; // just a starting point |
| 105 | int zlibResult = Z_BUF_ERROR; |
| 106 | |
| 107 | do { |
| 108 | result.alloc(compressedLen); |
| 109 | zlibResult = compress(result.data(), &compressedLen, bytes, length); |
| 110 | if (zlibResult == Z_BUF_ERROR) { |
| 111 | // the compressedArray needs to be larger |
| 112 | result.reset(); |
| 113 | compressedLen *= 2; |
| 114 | } else { |
| 115 | result.reset(); |
| 116 | result.alloc(compressedLen); |
| 117 | zlibResult = compress(result.data(), &compressedLen, bytes, length); |
| 118 | } |
| 119 | } while (zlibResult == Z_BUF_ERROR); |
| 120 | |
| 121 | return zlibResult == Z_OK; |
| 122 | } |
| 123 | |
| 124 | static bool tEXtToDataBuf(const byte* bytes, size_t length, DataBuf& result) { |
| 125 | static std::array<int, 256> value; |
no test coverage detected