+ // Do we need to decompress?
+ static int32_t magic = COMPRESS_MAGIC;
+ compressed = 0;
+ if ((in_data.size >= sizeof(struct CtdlCompressHeader)) && (!memcmp(in_data.data, &magic, sizeof(magic)))) {
+
+ // yes, we need to decompress
+ compressed = 1;
+ struct CtdlCompressHeader comp;
+ memcpy(&comp, in_data.data, sizeof(struct CtdlCompressHeader));
+ uncomp_data.size = comp.uncompressed_len;
+ uncomp_data.data = reallok(uncomp_data.data, uncomp_data.size);
+ destLen = (uLongf)comp.uncompressed_len;
+
+ ret = uncompress((Bytef *)uncomp_data.data, (uLongf *)&destLen,
+ (const Bytef *)in_data.data+sizeof(struct CtdlCompressHeader),
+ (uLong)comp.compressed_len);
+ if (ret != Z_OK) {
+ fprintf(stderr, "ctdldump: uncompress() error %d\n", ret);
+ exit(CTDLEXIT_DB);
+ }
+ }
+
+ // Call the export function registered to this table
+ export_functions[which_cdb](which_cdb, &in_key, (compressed ? &uncomp_data : &in_data));
+
+ // Knowing the total number of rows isn't critical to the program. It's just for the user to know.
+ fflush(stdout);
+ }