- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在我的 Ubuntu 机器上安装了 LZO,我想使用 ti 来压缩一个 char* 类型的字符串。
在示例文件中,我找到了这个代码片段(我已经为我的应用程序对它进行了一些编辑):
int r;
lzo_bytep in;
lzo_bytep out;
lzo_voidp wrkmem;
lzo_uint in_len;
lzo_uint out_len;
lzo_uint new_len;
int strToCompressLen; // I have added this
/*
* Step 1: initialize the LZO library
*/
if (lzo_init() != LZO_E_OK)
{
cout << "internal error - lzo_init() failed !!!" << endl;
cout << "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)" << endl;
//return 4;
}
// here I get the data I want to compress
char* imageData = (char*)imageIn->getFrame();
/*
* Step 2: allocate blocks and the work-memory
*/
strToCompressLen = strlen(imageData);
in = (lzo_bytep) xmalloc(strToCompressLen);
out = (lzo_bytep) xmalloc((strToCompressLen + strToCompressLen / 16 + 64 + 3));
wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS);
if (in == NULL || out == NULL || wrkmem == NULL)
{
cout << "out of memory" << endl;
//return 3;
}
/*
* Step 3: prepare the input block that will get compressed.
* We just fill it with zeros in this example program,
* but you would use your real-world data here.
*/
in_len = strToCompressLen;
lzo_memset(in,0,in_len);
/*
* Step 4: compress from 'in' to 'out' with LZO1X-1
*/
r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
if (r != LZO_E_OK)
{
/* this should NEVER happen */
cout << "internal error - compression failed: " << r << endl;
//return 2;
}
/* check for an incompressible block */
if (out_len >= in_len)
{
cout << "This block contains incompressible data." << endl;
//return 0;
}
但它所做的只是填充零。我需要压缩一个 char* 变量。
我想我需要编辑这些行:
in_len = strToCompressLen;
lzo_memset(in,0,in_len);
我在这个变量中有我想要压缩的字符串:
char* imageData = (char*)imageIn->getFrame();
我需要将其转换为其他类型吗?
LZO 的文档不是很有帮助(或者我可能无法正确使用它)。
最佳答案
主要有3个混淆点:
假设您可以使用 imageIn->getFrameSizeBytes() 之类的方法从 imageIn 获取图像的大小,试试这个:
int r;
lzo_bytep out;
lzo_voidp wrkmem;
lzo_uint out_len;
lzo_uint new_len;
/*
* Step 1: initialize the LZO library
*/
if (lzo_init() != LZO_E_OK)
{
cout << "internal error - lzo_init() failed !!!" << endl;
cout << "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)" << endl;
//return 4;
}
// here I get the data I want to compress
lzo_bytep imageData = (lzo_bytep) imageIn->getFrame();
size_t uncompressedImageSize = imageIn->getFrameSizeBytes();
/*
* Step 2: allocate blocks and the work-memory
*/
out = (lzo_bytep) xmalloc((uncompressedImageSize + uncompressedImageSize / 16 + 64 + 3));
wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS);
if (out == NULL || wrkmem == NULL)
{
cout << "out of memory" << endl;
//return 3;
}
/*
* Step 4: compress from 'imageData' to 'out' with LZO1X-1
*/
r = lzo1x_1_compress(imageData,uncompressedImageSize,out,&out_len,wrkmem);
if (r != LZO_E_OK)
{
/* this should NEVER happen */
cout << "internal error - compression failed: " << r << endl;
//return 2;
}
/* check for an incompressible block */
if (out_len >= uncompressedImageSize)
{
cout << "This block contains incompressible data." << endl;
//return 0;
}
不要忘记释放 wrkmem。更好的是,将 C++ 和 std::vector 用于工作内存,以便自动释放它。
关于c++ - LZO 压缩字符*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4219876/
我正在尝试使用 java-lzo 库解压缩压缩的字节数组。我正在关注this reference 。 我将以下 maven 依赖项添加到 pom.xml - org.anarre
我在两个目录中有一个 LZO 压缩文件,我需要将其解压缩,然后删除所有 LZO 压缩文件。 所以我在 /test01/primary 文件夹中有 LZO 压缩文件,我需要解压缩它,然后删除所有 .lz
用于 lzo-net ( http://lzo-net.sourceforge.net/ ) 我正在寻找新版本的 lzo.dll 文件。我的是 2004 年的。 最新的文件应该是 2.0.6 ( ht
我已经安装了 Cloudera Hadoop-LZO 软件包并将以下设置添加到我的客户端环境安全阀中: HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/opt/cloudera
我只是按照 Cloudera 文档中的步骤操作,在集群上安装了 GPL Extras Parcel,并通过 Cloudera Manager 配置了 HDFS 服务。但是尝试读取 HDFS 上的 .l
我正在尝试在我的 Java 程序中使用 LZO 压缩库 (http://www.oberhumer.com/opensource/lzo/)。我找不到一个示例如何使用它来压缩和解压缩数据。有人可以帮我
我已经在我的 Ubuntu 机器上安装了 LZO,我想使用 ti 来压缩一个 char* 类型的字符串。 在示例文件中,我找到了这个代码片段(我已经为我的应用程序对它进行了一些编辑): int r
我们在 s3 中有 3 个 .lzo 文件和相应的 .index 文件。我们正在这些文件的目录上创建一个外部表。每个 lzo 文件的大小为 100MB+,每个文件的未压缩大小为 800+MB bloc
非常感谢您阅读我的帖子。 我正在尝试在我的服务器(运行 Xeon CPU)上的 HBase 上安装 LZO 2.03 压缩编解码器。我目前正在运行 Hadoop 0.20.1 和 HBase 0.90
我正在设置 lzo 编解码器以用作我的 hadoop 作业中的压缩工具。我知道 lzo 具有创建可拆分文件的理想功能。但是我还没有找到让 lzo 自动创建可拆分文件的方法。到目前为止我读过的博客都提到
我在一个项目中使用 MiniLZO 来完成一些非常简单的压缩任务。我用一个程序压缩,用另一个程序解压缩。我想知道为解压缓冲区分配多少空间。我对过度分配空间没有意见,如果它可以省去我必须用整数注释我的输
我已经在fusecompress/安装了目录compressed/的fusecompress我将一个大文件(几GB)复制到fusecompress 目录(好吧,我对它进行了mv 处理)。目录compr
我们正在选择存储原始日志的文件格式,主要要求是压缩和可拆分。 block 压缩(以编解码器为准)SequenceFiles和 Hadoop-LZO到目前为止看起来最合适。 哪一个被Map-Reduce
在使用 TextInputFormat 时,Hadoop 似乎透明地处理压缩(这是什么时候引入的,我不记得是在 0.20.203 上)。不幸的是,当使用 LZO 压缩时,Hadoop 不使用 LZO
我正在尝试为 Hbase 设置 LZO 压缩。但是我在创建 build.xml 时遇到了问题。日志如下: anonymouse@hbase:~/omalley-hadoop-gpl-compressi
通常我会执行以下操作来使用 LZO: 使用lzop命令将数据文件压缩到本地磁盘。 放入HDFS。 使用分布式 lzo 索引器生成 .index 文件。 我想知道有没有办法同时对 HDFS 上的原始文件
尝试通过压缩运行mapreduce作业 hadoop jar \ /usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar \ rando
我需要安装 python-lzo-1.08。当我尝试从 gz 文件执行此操作时,出现错误: NameError:名称“CURL_DIR”未定义 操作系统:win7 我无法在任何地方找到 Windows
我有一些使用 lzo 压缩的 tsv 格式的数据。现在,我想在 java Spark 程序中使用这些数据。 目前,我可以解压这些文件,然后使用 将它们作为文本文件导入到 Java 中 Spar
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我是一名优秀的程序员,十分优秀!