miniLZO压缩库使用注意事项

来源:互联网 发布:mac口红russian red 编辑:程序博客网 时间:2024/04/26 00:51

 使用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;    }



原创粉丝点击