MCPcopy Create free account
hub / github.com/F-Stack/f-stack / FIO_compressGzFrame

Function FIO_compressGzFrame

freebsd/contrib/zstd/programs/fileio.c:1020–1098  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1018
1019#ifdef ZSTD_GZCOMPRESS
1020static unsigned long long
1021FIO_compressGzFrame(const cRess_t* ress, /* buffers & handlers are used, but not changed */
1022 const char* srcFileName, U64 const srcFileSize,
1023 int compressionLevel, U64* readsize)
1024{
1025 unsigned long long inFileSize = 0, outFileSize = 0;
1026 z_stream strm;
1027
1028 if (compressionLevel > Z_BEST_COMPRESSION)
1029 compressionLevel = Z_BEST_COMPRESSION;
1030
1031 strm.zalloc = Z_NULL;
1032 strm.zfree = Z_NULL;
1033 strm.opaque = Z_NULL;
1034
1035 { int const ret = deflateInit2(&strm, compressionLevel, Z_DEFLATED,
1036 15 /* maxWindowLogSize */ + 16 /* gzip only */,
1037 8, Z_DEFAULT_STRATEGY); /* see http://www.zlib.net/manual.html */
1038 if (ret != Z_OK) {
1039 EXM_THROW(71, "zstd: %s: deflateInit2 error %d \n", srcFileName, ret);
1040 } }
1041
1042 strm.next_in = 0;
1043 strm.avail_in = 0;
1044 strm.next_out = (Bytef*)ress->dstBuffer;
1045 strm.avail_out = (uInt)ress->dstBufferSize;
1046
1047 while (1) {
1048 int ret;
1049 if (strm.avail_in == 0) {
1050 size_t const inSize = fread(ress->srcBuffer, 1, ress->srcBufferSize, ress->srcFile);
1051 if (inSize == 0) break;
1052 inFileSize += inSize;
1053 strm.next_in = (z_const unsigned char*)ress->srcBuffer;
1054 strm.avail_in = (uInt)inSize;
1055 }
1056 ret = deflate(&strm, Z_NO_FLUSH);
1057 if (ret != Z_OK)
1058 EXM_THROW(72, "zstd: %s: deflate error %d \n", srcFileName, ret);
1059 { size_t const cSize = ress->dstBufferSize - strm.avail_out;
1060 if (cSize) {
1061 if (fwrite(ress->dstBuffer, 1, cSize, ress->dstFile) != cSize)
1062 EXM_THROW(73, "Write error : cannot write to output file : %s ", strerror(errno));
1063 outFileSize += cSize;
1064 strm.next_out = (Bytef*)ress->dstBuffer;
1065 strm.avail_out = (uInt)ress->dstBufferSize;
1066 } }
1067 if (srcFileSize == UTIL_FILESIZE_UNKNOWN) {
1068 DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ",
1069 (unsigned)(inFileSize>>20),
1070 (double)outFileSize/inFileSize*100)
1071 } else {
1072 DISPLAYUPDATE(2, "\rRead : %u / %u MB ==> %.2f%% ",
1073 (unsigned)(inFileSize>>20), (unsigned)(srcFileSize>>20),
1074 (double)outFileSize/inFileSize*100);
1075 } }
1076
1077 while (1) {

Callers 1

Calls 2

deflateFunction · 0.85
deflateEndFunction · 0.85

Tested by

no test coverage detected