- z_stream stream;
- int max_out_bytes = namelen + st->st_size + 200;
- void *out = malloc(max_out_bytes);
- void *metadata = malloc(namelen + 200);
- void *in = mmap(NULL, st->st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- SHA_CTX c;
-
- close(fd);
- if (!out || (int)(long)in == -1)
- return -1;
-
- memset(&stream, 0, sizeof(stream));
- deflateInit(&stream, Z_BEST_COMPRESSION);
-
- /*
- * ASCII size + nul byte
- */
- stream.next_in = metadata;
- stream.avail_in = 1+sprintf(metadata, "blob %lu", (unsigned long) st->st_size);
- stream.next_out = out;
- stream.avail_out = max_out_bytes;
- while (deflate(&stream, 0) == Z_OK)
- /* nothing */;