现在的位置: 首页 > 综合 > 正文

miniLZO压缩库使用注意事项

2013年09月19日 ⁄ 综合 ⁄ 共 827字 ⁄ 字号 评论关闭

 使用miniLZO压缩库的好处不多说了。下面是一个在实际使用中需注意的地方:

解压缩函数(下面任何一个):

/* decompression */
LZO_EXTERN(int)
lzo1x_decompress        ( const lzo_bytep src, lzo_uint  src_len,
                                lzo_bytep dst, lzo_uintp dst_len,
                                lzo_voidp wrkmem /* NOT USED */ );

/* safe decompression with overrun testing */
LZO_EXTERN(int)
lzo1x_decompress_safe   ( const lzo_bytep src, lzo_uint  src_len,
                                lzo_bytep dst, lzo_uintp dst_len,
                                lzo_voidp wrkmem /* NOT USED */ );

中的第四个参数,即“解压缩后的”长度,虽然是一个指针型(要返回的内容),但却是需要输入“压缩前的长度值“,这一点一定注意!

实际上,在miniLZO压缩库给的testmini.c中已经看出来:

/*
 * Step 4: decompress again, now going from 'out' to 'in'
 */
    new_len = in_len;//!!!!
    r = lzo1x_decompress(out,out_len,in,&new_len,NULL);
    if (r == LZO_E_OK && new_len == in_len)
        printf("decompressed %lu bytes back into %lu bytes\n",
            (unsigned long) out_len, (unsigned long) in_len);
    else
    {
        /* this should NEVER happen */
        printf("internal error - decompression failed: %d\n", r);
        return 1;
    }

抱歉!评论已关闭.