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

Function recompress

freebsd/contrib/zstd/zlibWrapper/examples/fitblk.c:103–133  ·  view source on GitHub ↗

recompress from inf's input to def's output; the input for inf and the output for def are set in those structures before calling; return last deflate() return value, or Z_MEM_ERROR if inflate() was not able to allocate enough memory when it needed to */

Source from the content-addressed store, hash-verified

101 return last deflate() return value, or Z_MEM_ERROR if inflate()
102 was not able to allocate enough memory when it needed to */
103local int recompress(z_streamp inf, z_streamp def)
104{
105 int ret, flush;
106 unsigned char raw[RAWLEN];
107
108 flush = Z_NO_FLUSH;
109 LOG_FITBLK("recompress start\n");
110 do {
111 /* decompress */
112 inf->avail_out = RAWLEN;
113 inf->next_out = raw;
114 LOG_FITBLK("recompress1inflate avail_in=%d total_in=%d avail_out=%d total_out=%d\n", (int)inf->avail_in, (int)inf->total_in, (int)inf->avail_out, (int)inf->total_out);
115 ret = inflate(inf, Z_NO_FLUSH);
116 LOG_FITBLK("recompress2inflate avail_in=%d total_in=%d avail_out=%d total_out=%d\n", (int)inf->avail_in, (int)inf->total_in, (int)inf->avail_out, (int)inf->total_out);
117 assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR &&
118 ret != Z_NEED_DICT);
119 if (ret == Z_MEM_ERROR)
120 return ret;
121
122 /* compress what was decompresed until done or no room */
123 def->avail_in = RAWLEN - inf->avail_out;
124 def->next_in = raw;
125 if (inf->avail_out != 0)
126 flush = Z_FINISH;
127 LOG_FITBLK("recompress1deflate avail_in=%d total_in=%d avail_out=%d total_out=%d\n", (int)def->avail_in, (int)def->total_in, (int)def->avail_out, (int)def->total_out);
128 ret = deflate(def, flush);
129 LOG_FITBLK("recompress2deflate ret=%d avail_in=%d total_in=%d avail_out=%d total_out=%d\n", ret, (int)def->avail_in, (int)def->total_in, (int)def->avail_out, (int)def->total_out);
130 assert(ret != Z_STREAM_ERROR);
131 } while (ret != Z_STREAM_END && def->avail_out != 0);
132 return ret;
133}
134
135#define EXCESS 256 /* empirically determined stream overage */
136#define MARGIN 8 /* amount to back off for completion */

Callers 1

mainFunction · 0.70

Calls 1

deflateFunction · 0.85

Tested by

no test coverage detected