easylzma C语言压缩库

程序名称:easylzma

授权协议: 未知

操作系统: 跨平台

开发语言: C/C++

easylzma 介绍

Easylzma 是一个实现了 LZMA 压缩和解压缩算法的 C 语言库。

LZMA ,( _Lempel -Ziv-Markov chain-Algorithm_的縮寫),是
2001年以來得到發展的一個數據壓縮演算法,它用於 7-Zip 歸檔工具中的 7z 格式。它使用類似於 LZ77 的字典編碼機制,在一般的情況下壓縮率比
bzip2 為高,用於壓縮的字典檔大小可達4GB。

示例代码:

/
an example of basic LZMA compression to and from memory buffers
using the easylzma library.
/

include “easylzma/compress.h”

include

include

struct dataStream
{
const unsigned char * inData;
size_t inLen;

unsigned char * outData;
size_t outLen;
};

/ an input callback that will be passed to elzma_compress_run(),
it reads from a memory buffer /
static int
inputCallback(void
ctx, void buf, size_t * size)
{
size_t rd = 0;
struct dataStream * ds = (struct dataStream
) ctx;
assert(ds != NULL);

rd = (ds->inLen < size) ? ds->inLen : size;

if (rd > 0) {
memcpy(buf, (void *) ds->inData, rd);
ds->inData += rd;
ds->inLen -= rd;
}

*size = rd;

return 0;
}

/ an ouput callback that will be passed to elzma_compress_run(),
it reallocs and writes to a memory buffer /
static size_t
outputCallback(void
ctx, const void buf, size_t size)
{
struct dataStream * ds = (struct dataStream
) ctx;
assert(ds != NULL);

if (size > 0) {
ds->outData = realloc(ds->outData, ds->outLen + size);
memcpy((void *) (ds->outData + ds->outLen), buf, size);
ds->outLen += size;
}

return size;
}

/ a function that will compress data using a 1mb dictionary and a
client specified encoding format (one of ELZMA_lzip or ELZMA_lzma) /
int
simpleCompress(elzma_file_format format, const unsigned char * inData,
size_t inLen, unsigned char
* outData,
size_t * outLen)
{
int rc;
elzma_compress_handle hand;

/ allocate compression handle /
hand = elzma_compress_alloc();
assert(hand != NULL);

/ configure the compression run with mostly default parameters /
rc = elzma_compress_config(hand, ELZMA_LC_DEFAULT,
ELZMA_LP_DEFAULT, ELZMA_PB_DEFAULT,
5, (1 << 20) / 1mb /,
format, inLen);

/ fail if we couldn’t allocate /
if (rc != ELZMA_E_OK) {
elzma_compress_free(&hand);
return rc;
}

/ now run the compression /
{
/ set up the context structure that will be passed to
stream callbacks */
struct dataStream ds;
ds.inData = inData;
ds.inLen = inLen;
ds.outData = NULL;
ds.outLen = 0;

/ run the streaming compression /
rc = elzma_compress_run(hand, inputCallback, (void ) &ds,
outputCallback, (void
) &ds);

if (rc != ELZMA_E_OK) {
if (ds.outData != NULL) free(ds.outData);
elzma_compress_free(&hand);
return rc;
}

outData = ds.outData;
outLen = ds.outLen;
}

return rc;
}

easylzma 官网

http://lloyd.github.com/easylzma/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Pacman 是一个软件包管理器, 作为 ArchLinux 发行版的一部分.
Smb4K 是KDE下的网络共享浏览器 更多屏幕截图请看:http://developer.berlios.de/screenshots/?group_id=769
Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如
虚拟桌面软件,可管理最多9个虚拟桌面,你可以用热键进行桌面切换
UNetbootin (Universal Netboot Installer)为一种跨平台工具软件,可以用来建立Live USB 系统,也可以加载各种系统工具,或安装各种Linux操作系统(Linux套件)和其他操作系统,不需使用安装光碟(自 动透过网络下
Cobbler 可以用来快速建立 Linux 网络安装环境,它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会。
Wubi是用于在Windows操作系统中安装Ubuntu的工具软件,Wubi中的W代表Windows Lubi和Wubi是兄弟项目,目的都是为了方便用户安装Ubuntu(也支持其他的Linux发行版,如Fedora),Lubi和Wubi两者工作的平台不同,但都具
KCalendar 允许被嵌入到你的 Linux 桌面,并支持显示包括农历日期、24 节气、农历节日、农历生日、阳历生日、阳历节日、阳历纪念日、周节日等在内的各种内容,尤其适合咱中文用户使用。
IPodWizard 让你可以定制你的 iPod 上的不同的图标,文本串和字体.该软件不仅可以直接地连接到你的 iPod
QEMU 是一套由Fabrice Bellard所编写的模拟处理器的自由软件。它与Bochs,PearPC近似,但其具有某些后两者所不具备的特性,如高速度及跨平台的特性。经由kqemu这个开源的加速器,QEMU能模拟至接近真实电脑的速度。
Launchy 是一款免费开源的协助您摒弃 Windows “运行”的 Dock 式替代工具,既方便又实用,自带多款皮肤,作为美化工具也未尝不可。Launchy
Apache Toolbox 是一个可以大大提高linux下apache(一种web服务器) 的安装配置效率的工具软件。Apache
AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows
每当你安装完一个新的系统,打完繁多的SP和Hotfix以后执行一下xpy是一个非常省事的主意:)xpy这个小工 具只有73K大小,
syslinux是一个轻量级的启动装载器,只用Windows的人可能不明白是什么东西,如果玩过Linux,一定知道lilo和grub,是的,所谓轻量级我想就是跟grub们相比而言的,尤其是grub2。
GRUB是一个多重启动管理器。GRUB是GRand Unified Bootloader的缩写,它可以在多个操作系统共存时选择引导哪个系统。它可以引导几乎所有的Unix,Linux,Windows操作系统。它可以
bash 是一个为GNU项目编写的Unix shell。它的名字是一系列缩写: B ourne- A gain SH ell
AppleJack 是一个对使用者很友好的故障诊断工具,适用于 Mac OS X 平台。
Gujin 是一个 PC 的启动加载器,可分析你的分区和文件系统。可查找可用的 Linux
Ubuntu Tweak 是一款专门为Ubuntu准备的配置、调整工具。不论您是新手还是老手,都将从这个工具中获取帮助。