int pread_compressed(Db *db, off_t pos, char **ret_ptr)
{
    char *compressed_buf;
    char *new_buf;
    int len = pread_bin_internal(db, pos, &compressed_buf, 0);
    if (len < 0) {
        return len;
    }
    size_t uncompressed_len;
    if (snappy_uncompressed_length(compressed_buf, len, &uncompressed_len) != SNAPPY_OK) {
        //should be compressed but snappy doesn't see it as valid.
        free(compressed_buf);
        return COUCHSTORE_ERROR_CORRUPT;
    }

    new_buf = (char *) malloc(uncompressed_len);
    if (!new_buf) {
        free(compressed_buf);
        return COUCHSTORE_ERROR_ALLOC_FAIL;
    }
    snappy_status ss = (snappy_uncompress(compressed_buf, len, new_buf, &uncompressed_len));
    free(compressed_buf);
    if (ss != SNAPPY_OK) {
        return COUCHSTORE_ERROR_CORRUPT;
    }

    *ret_ptr = new_buf;
    return (int) uncompressed_len;
}
int pread_header(Db *db, off_t pos, char **ret_ptr)
{
    return pread_bin_internal(db, pos + 1, ret_ptr, 1);
}
Exemple #3
0
int pread_bin(tree_file *file, cs_off_t pos, char **ret_ptr)
{
    return pread_bin_internal(file, pos, ret_ptr, 0);
}
int pread_bin(Db *db, off_t pos, char **ret_ptr)
{
    return pread_bin_internal(db, pos, ret_ptr, 0);
}
Exemple #5
0
int pread_header(tree_file *file, cs_off_t pos, char **ret_ptr)
{
    return pread_bin_internal(file, pos + 1, ret_ptr, 1);
}