Exemplo n.º 1
0
static SquashStatus
squash_libdeflate_decompress_buffer (SquashCodec* codec,
                                size_t* decompressed_size,
                                uint8_t decompressed[HEDLEY_ARRAY_PARAM(*decompressed_size)],
                                size_t compressed_size,
                                const uint8_t compressed[HEDLEY_ARRAY_PARAM(compressed_size)],
                                SquashOptions* options) {
  struct deflate_decompressor *decompressor = deflate_alloc_decompressor();
  size_t actual_out_nbytes;
  enum decompress_result ret = deflate_decompress(decompressor, compressed, compressed_size,
                                             decompressed, *decompressed_size, &actual_out_nbytes);
  deflate_free_decompressor(decompressor);
  *decompressed_size = actual_out_nbytes;
  switch (ret) {
    case DECOMPRESS_SUCCESS:
      return SQUASH_OK;
    case DECOMPRESS_BAD_DATA:
      return squash_error (SQUASH_FAILED);
    case DECOMPRESS_SHORT_OUTPUT:
      return squash_error (SQUASH_BUFFER_FULL);
    case DECOMPRESS_INSUFFICIENT_SPACE:
      return squash_error (SQUASH_BUFFER_FULL);
  }

  HEDLEY_UNREACHABLE ();
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	struct deflate_decompressor *d;
	int ret;
	int fd = open(argv[1], O_RDONLY);
	struct stat stbuf;
	assert(fd >= 0);
	ret = fstat(fd, &stbuf);
	assert(!ret);

	char in[stbuf.st_size];
	ret = read(fd, in, sizeof in);
	assert(ret == sizeof in);

	char out[sizeof(in) * 3];

	d = deflate_alloc_decompressor();

	zlib_decompress(d, in, sizeof in, out, sizeof out, NULL);
	deflate_free_decompressor(d);
	return 0;
}