| 1101 | |
| 1102 | #ifdef ZSTD_LZMACOMPRESS |
| 1103 | static unsigned long long |
| 1104 | FIO_compressLzmaFrame(cRess_t* ress, |
| 1105 | const char* srcFileName, U64 const srcFileSize, |
| 1106 | int compressionLevel, U64* readsize, int plain_lzma) |
| 1107 | { |
| 1108 | unsigned long long inFileSize = 0, outFileSize = 0; |
| 1109 | lzma_stream strm = LZMA_STREAM_INIT; |
| 1110 | lzma_action action = LZMA_RUN; |
| 1111 | lzma_ret ret; |
| 1112 | |
| 1113 | if (compressionLevel < 0) compressionLevel = 0; |
| 1114 | if (compressionLevel > 9) compressionLevel = 9; |
| 1115 | |
| 1116 | if (plain_lzma) { |
| 1117 | lzma_options_lzma opt_lzma; |
| 1118 | if (lzma_lzma_preset(&opt_lzma, compressionLevel)) |
| 1119 | EXM_THROW(81, "zstd: %s: lzma_lzma_preset error", srcFileName); |
| 1120 | ret = lzma_alone_encoder(&strm, &opt_lzma); /* LZMA */ |
| 1121 | if (ret != LZMA_OK) |
| 1122 | EXM_THROW(82, "zstd: %s: lzma_alone_encoder error %d", srcFileName, ret); |
| 1123 | } else { |
| 1124 | ret = lzma_easy_encoder(&strm, compressionLevel, LZMA_CHECK_CRC64); /* XZ */ |
| 1125 | if (ret != LZMA_OK) |
| 1126 | EXM_THROW(83, "zstd: %s: lzma_easy_encoder error %d", srcFileName, ret); |
| 1127 | } |
| 1128 | |
| 1129 | strm.next_in = 0; |
| 1130 | strm.avail_in = 0; |
| 1131 | strm.next_out = (BYTE*)ress->dstBuffer; |
| 1132 | strm.avail_out = ress->dstBufferSize; |
| 1133 | |
| 1134 | while (1) { |
| 1135 | if (strm.avail_in == 0) { |
| 1136 | size_t const inSize = fread(ress->srcBuffer, 1, ress->srcBufferSize, ress->srcFile); |
| 1137 | if (inSize == 0) action = LZMA_FINISH; |
| 1138 | inFileSize += inSize; |
| 1139 | strm.next_in = (BYTE const*)ress->srcBuffer; |
| 1140 | strm.avail_in = inSize; |
| 1141 | } |
| 1142 | |
| 1143 | ret = lzma_code(&strm, action); |
| 1144 | |
| 1145 | if (ret != LZMA_OK && ret != LZMA_STREAM_END) |
| 1146 | EXM_THROW(84, "zstd: %s: lzma_code encoding error %d", srcFileName, ret); |
| 1147 | { size_t const compBytes = ress->dstBufferSize - strm.avail_out; |
| 1148 | if (compBytes) { |
| 1149 | if (fwrite(ress->dstBuffer, 1, compBytes, ress->dstFile) != compBytes) |
| 1150 | EXM_THROW(85, "Write error : %s", strerror(errno)); |
| 1151 | outFileSize += compBytes; |
| 1152 | strm.next_out = (BYTE*)ress->dstBuffer; |
| 1153 | strm.avail_out = ress->dstBufferSize; |
| 1154 | } } |
| 1155 | if (srcFileSize == UTIL_FILESIZE_UNKNOWN) |
| 1156 | DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%%", |
| 1157 | (unsigned)(inFileSize>>20), |
| 1158 | (double)outFileSize/inFileSize*100) |
| 1159 | else |
| 1160 | DISPLAYUPDATE(2, "\rRead : %u / %u MB ==> %.2f%%", |
no outgoing calls
no test coverage detected