예제 #1
0
static void
test_bm_unpack(const char *in, size_t len, char *out, size_t *len_p) {
  int ret = bmz_bm_unpack(in, len, out, len_p);
  LOG(1, "\nbm_unpack returned %d, size: %lu\n", ret, (Lu)*len_p);
  if (s_verbosity < 2) return;
  puts("bm decoded:");
  fwrite(out, 1, *len_p, stdout);
  puts("\nend-decoded");
}
예제 #2
0
파일: bmz.c 프로젝트: nkhuyu/hypertable
int
bmz_unpack(const void *in, size_t in_len, void *out, size_t *out_len_p,
           void *work_mem) {
  Byte *dst = (Byte *)work_mem;
  size_t tlen = *out_len_p + 1;
  int ret;

  ret = bmz_lz_unpack((Byte *)in, in_len, dst, &tlen);
  if (ret != BMZ_E_OK) return ret;
  return bmz_bm_unpack(dst, tlen, out, out_len_p);
}
예제 #3
0
static void
do_unpack(const void *in, size_t in_len, size_t buf_len) {
  const Byte *bp = (Byte *)in;
  uint16_t version;
  uint64_t orig_size;
  uint32_t checksum, cs, options;
  size_t outlen, worklen, len = in_len - BMZ_HEADER_SZ;
  Byte *out, *workmem;
  int ret;

  if (in_len < BMZ_HEADER_SZ) DIE("file truncated (size: %lu)", (Lu)in_len);

  parse_bmz_header(bp, &version, &orig_size, &checksum, &options);

  if (orig_size > INT_MAX && sizeof(size_t) == 4)
    DIE("original file size %llu requires 64-bit version of bmzip",
        (Llu)orig_size);

  bp += BMZ_HEADER_SZ;
  buf_len -= BMZ_HEADER_SZ;
  cs = bmz_checksum(bp, len);
  outlen = orig_size;

  if (cs != checksum)
    DIE("checksum mismatch (expecting %x, got %x).", checksum, cs);

  if (options & BMZ_O_BM_ONLY) {
    out = buf_len > in_len + orig_size ? (Byte*)bp + len : malloc(outlen);

    if ((ret = bmz_bm_unpack(bp, len, out, &outlen)) != BMZ_E_OK)
      DIE("error decoding bm input (error %d)", ret);
  }
  else {
    worklen = bmz_unpack_worklen(orig_size > len ? orig_size : len);
    out = (buf_len > outlen + worklen) ? (Byte *)bp : malloc(outlen + worklen);
    workmem = out + outlen;

    if ((ret = bmz_unpack(bp, len, out, &outlen, workmem)) != BMZ_E_OK)
      DIE("error decompressing (error %d)", ret);
  }
  if (orig_size != outlen)
    WARN("size mismatch (expecting %llu, got %llu)",
         (Llu)orig_size, (Llu)outlen);

  write(1, out, outlen);
}