- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为miniz-cpp的zlib压缩实现编写一个简单的C++包装。通货紧缩可以解决,但现在又出现了数据膨胀问题。
码
我有一个测试用例(大致简化)归结为:
ByteArray randomData = createRandomData(1024 * 1024);
ByteArray deflatedBytes = deflate(randomData);
writeToTmpFile(deflatedBytes); // for manual review
ByteArray inflatedBytes = inflate(deflatedBytes);
assert(randomData == inflatedBytes);
我被卡在
DATA_ERROR (-3)
上,当我再次为数据充气时会返回它。
// inflates the next <size> bytes and stores them in <out[]>
// stores the actually written amount in <written>
ResultCode Inflator::inflate(uint8_t out[], size_t size, size_t& written)
{
zStream.next_out = out;
zStream.avail_out = static_cast<unsigned int>(size);
// loop until output buffer is completely filled
while (zStream.avail_out != 0) {
if (zStream.avail_in == 0) {
// our Inflator stores a ByteArrayInputStream from which
// we request more data
size_t read = iStream.read(in, BUFFER_SIZE);
if (iStream.err()) {
return ResultCode::STREAM_ERROR;
}
zStream.next_in = in;
zStream.avail_in = static_cast<unsigned int>(read);
}
// THIS IS WHERE WE ACTUALLY CALL INFLATE.
// RESULT CODE -3 (DATA_ERROR) IS RETURNED AFTER READING
// ONLY 13 BYTES.
ResultCode result{mz_inflate(&zStream, Flushing::NONE)};
if (result == ResultCode::STREAM_END) {
written = size - zStream.avail_out;
this->eof_ = true;
return ResultCode::OK;
}
else if (result != ResultCode::OK) {
return result;
}
}
written = size - zStream.avail_out;
return ResultCode::OK;
}
我的资料
zStream
(即
mz_stream
)在
next_in
中具有数据,该数据是有效的zlib编码数据。至少它以
0x78
开头。
# this command is included in the qpdf package and uncompresses zlib streams
zlib-flate -uncompress < 'mve_deflOutput.zlib' > 'mve_deflOutput.bin'
这也是前几个字节的十六进制转储:
00000000: 7801 a4dd fb7f cfe5 1b07 7072 c8a9 9632 x.........pr...2
00000010: 49ac 9043 9a4c 392c 462c 4d88 8ab0 4a7c I..C.L9,F,M...J|
00000020: 55d6 2c6d 6921 0931 34ad 4db5 8898 1c26 U.,mi!.14.M....&
00000030: 3a88 ce69 51d9 6a52 94a8 302d d252 6ba6 :..iQ.jR..0-.Rk.
00000040: 84a2 b2ef 9ff0 fce1 be7f dd63 dbe7 f37e ...........c...~
00000050: dff7 75bd aed7 eb75 5df7 11ac 4358 3763 ..u....u]...CX7c
00000060: b5c0 ea88 550f ab33 d62e aca7 b132 b116 ....U..3.....2..
00000070: 611d c73a 8935 096b 0d56 05d6 8758 a3b1 a..:.5.k.V...X..
00000080: f0ef d7b4 c5c2 bfff f027 2c3c be93 b5b1 .........',<....
00000090: cec2 1a80 7531 5612 d68d 583b b0d6 622d ....u1V...X;..b-
错误
mz_inflate
的
inflate
的调用都会返回
DATA_ERROR (-3)
。
total_in
中的
zStream
字段设置为13,因此看起来在错误发生之前仅读取了13个字节。
zlib-flate
提取,那么为什么不能最小化读取此数据?它是按字面意思写的。如果前13个字节有问题,我看不到可能是什么。
Inflator
and the test.
最佳答案
这是一个防反跳的解决方案,但事实证明,我应该使用实际的 miniz
而不是 miniz-cpp
的单头镜像。这个单头库使用的是自2017年以来库的严重过时版本,根本无法正确读取数据。
当使用实际的miniz
时,测试通过了,一切正常。我的代码100%正确,只是使用了错误的库。
关于c++ - 读取zlib/miniz压缩数据时出现DATA_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63539054/
起初,我只想在 python3.2 中使用 install feedparser,而它需要 Distribute。当我安装 Distribute 时 python3.2 setup.py instal
我正在尝试在另一台计算机上安装我的 Yesod Web 应用程序。 我已经在我当前的机器上很好地安装了它,并且可以cabal install它在那里没有任何问题。 我似乎在另一台机器上遇到了麻烦(这是
https://www.ietf.org/rfc/rfc1951.txt 的“3.2.7. 使用动态霍夫曼代码压缩(BTYPE=10)”部分描述了压缩期间使用的动态哈夫曼树的编码。可能出现在 DEFL
给定 Elixir 中代表压缩文件的二进制文件,我如何将它们传递到 Erlang 的 zlib 进行膨胀? compressed = > 我已经尝试过: z = :zlib.open() uncomp
我知道 zlib/miniz 提供了 compressBound,它根据纯文本大小返回压缩/压缩大小的上限。这很方便。 是否有用于返回膨胀/解压缩大小上限的膨胀函数(zlib/miniz)?还是一个简
我有一组存储在数据库中的 ZLIB 压缩/base64 编码字符串(在 C 程序中完成)。我编写了一个小型 PHP 页面,应该检索这些值并绘制它们(字符串最初是 float 列表)。 压缩/编码的 C
在https://www.rfc-editor.org/rfc/rfc1951 Note that in the "deflate" format, the Huffman codes for the
在https://www.rfc-editor.org/rfc/rfc1951 Note that in the "deflate" format, the Huffman codes for the
我正在处理处理较大文件的项目,在我们的代码库中,我们会返回寻找写入证书信息,这些寻找的范围大部分时间都非常小,我想在我的流写入器/读取器中使用 zlib为了节省磁盘空间,但由于这样的搜索我无法集成它,
我正在尝试使用以下命令升级 Node 版本:npm install npm@latest -g 命令。但它给出了 zlib 绑定(bind)关闭错误。 有办法解决这个问题吗? 最佳答案 你的 No
这个问题在这里已经有了答案: no module named zlib (9 个回答) 关闭 4 年前。 # pythonbrew venv create django1.5 Creating `d
本文整理了Java中io.gomint.server.jni.zlib.ZLib.process()方法的一些代码示例,展示了ZLib.process()的具体用法。这些代码示例主要来源于Github
本文整理了Java中io.gomint.server.jni.zlib.ZLib.init()方法的一些代码示例,展示了ZLib.init()的具体用法。这些代码示例主要来源于Github/Stack
我想使用 python zlib 压缩文本,并通过 Apache Thrift 发送压缩文本,最后我用 Java 解压了压缩文本。 但我不知道该怎么做。我找不到任何像 Java 中的 python z
是否有允许使用 Zlib 压缩数据的类,或者直接使用 zlib.dylib 是我唯一的可能吗? 最佳答案 NSData+Compression 是一个易于使用的 NSData 类别实现。 NSData
我使用 rvm 安装了 zlib 包和 ruby 1.9.3,但是每当我尝试安装时它说的 gem 无法加载此类文件--zlib 我用来安装的命令是 $ rvm install 1.9.3 $ rv
在 Django Design Patterns ,作者建议使用 zlib.crc32 来屏蔽 URL 中的主键。经过一些快速测试后,我注意到 crc32 大约有一半的时间会生成负整数,这似乎不适合在
我想以 ZLIB 格式在我的 C# 和 C++ 应用程序之间发送压缩数据。在 C++ 中,我使用 boost::iostreams 中可用的 zlib_compressor/zlib_decompre
我在 Python 和 C 中对 crc32 进行了一些试验,但我的结果不匹配。 C: #include #include #include #define NUM_BYTES 9 int ma
来自 ./configure --help: --with-zlib=DIR Include ZLIB support (requires zlib >= 1.0.9) --with-zlib-
我是一名优秀的程序员,十分优秀!