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

Function gz_compress

freebsd/contrib/zstd/zlibWrapper/examples/minigzip.c:367–393  ·  view source on GitHub ↗
(in, out)

Source from the content-addressed store, hash-verified

365 */
366
367void gz_compress(in, out)
368 FILE *in;
369 gzFile out;
370{
371 local char buf[BUFLEN];
372 int len;
373 int err;
374
375#ifdef USE_MMAP
376 /* Try first compressing with mmap. If mmap fails (minigzip used in a
377 * pipe), use the normal fread loop.
378 */
379 if (gz_compress_mmap(in, out) == Z_OK) return;
380#endif
381 for (;;) {
382 len = (int)fread(buf, 1, sizeof(buf), in);
383 if (ferror(in)) {
384 perror("fread");
385 exit(1);
386 }
387 if (len == 0) break;
388
389 if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
390 }
391 fclose(in);
392 if (gzclose(out) != Z_OK) error("failed gzclose");
393}
394
395#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
396

Callers 2

file_compressFunction · 0.70
mainFunction · 0.70

Calls 4

gz_compress_mmapFunction · 0.70
gzwriteFunction · 0.70
errorFunction · 0.70
gzcloseFunction · 0.70

Tested by

no test coverage detected