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

Function gz_compress

freebsd/contrib/zlib/test/minigzip.c:362–388  ·  view source on GitHub ↗
(in, out)

Source from the content-addressed store, hash-verified

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

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