Android NDK zlib 返回 Z_DATA_ERROR 以获得有效的邮政编码信息

发布于 2024-11-10 17:14:50 字数 1193 浏览 2 评论 0原文

我正在执行以下操作来解压缩压缩数据块:

z_stream stream;
int err;

int nExtraChunks;
uInt destlen;

stream.next_in = (Bytef*)pSrc;
stream.avail_in = (uInt)nSrcLen;
destlen = (uInt)*pnDestLen;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;

err = inflateInit(&stream);
if (err != Z_OK) 
    return err;

nExtraChunks = 0;
do {
    stream.next_out = pDest;
    stream.avail_out = destlen;
    err = inflate(&stream, Z_FINISH);
    if (err == Z_STREAM_END )
        break;
    if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
    {
        err = Z_DATA_ERROR;
    }
    if (err != Z_BUF_ERROR) 
    {
        inflateEnd(&stream);
        return err;
    }
    nExtraChunks += 1;
} while (stream.avail_out == 0);

*pnDestLen = stream.total_out;

err = inflateEnd(&stream);
if (err != Z_OK) return err;

return nExtraChunks ? Z_BUF_ERROR : Z_OK;

其中 pSrc 和 nSrcLen、pDest 和 destLen 给出了内存块及其各自的长度。 pSrc 保存有效 zip 文件的内容。

(此例程改编自 easyzlib 驱动程序函数,但我直接使用 NDK 提供的 zlib。)

对于我进行的每次调用,第一个 inflate 调用都会返回 -3 (Z_DATA_ERROR)。我通过将内存块写入磁盘、执行“adb pull”将其下载到我的 mac 并进行压缩来确认 zip 是有效的。我不太了解 zlib...我能做些什么来调试这个?

I'm doing the following to decompress a block of zipped data:

z_stream stream;
int err;

int nExtraChunks;
uInt destlen;

stream.next_in = (Bytef*)pSrc;
stream.avail_in = (uInt)nSrcLen;
destlen = (uInt)*pnDestLen;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;

err = inflateInit(&stream);
if (err != Z_OK) 
    return err;

nExtraChunks = 0;
do {
    stream.next_out = pDest;
    stream.avail_out = destlen;
    err = inflate(&stream, Z_FINISH);
    if (err == Z_STREAM_END )
        break;
    if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
    {
        err = Z_DATA_ERROR;
    }
    if (err != Z_BUF_ERROR) 
    {
        inflateEnd(&stream);
        return err;
    }
    nExtraChunks += 1;
} while (stream.avail_out == 0);

*pnDestLen = stream.total_out;

err = inflateEnd(&stream);
if (err != Z_OK) return err;

return nExtraChunks ? Z_BUF_ERROR : Z_OK;

where pSrc and nSrcLen, pDest and destLen are given blocks of memory and their respective lengths. pSrc holds the contents of a valid zip file.

(This routine is adapted from the easyzlib driver function but I'm using the NDK-supplied zlib directly.)

The first inflate call returns -3 (Z_DATA_ERROR) for every call I make. I've confirmed that the zip is valid by writing the block of memory to disk, doing and "adb pull" to download it to my mac and gunzipping it. I don't know zlib very well... what can I do to debug this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-11-17 17:14:50

正如我提到的,我使用 Mac 进行开发。我用“zip”压缩文件,这显然是不行的。尽管“unzip”和“gunzip”都可以很好地处理文件,但情况确实如此。您必须使用 gzip 来最终获得 Android NDK 的 libz 可以处理的存档。至于“如何调试这种事情”这个问题,我仍然没有一个好的答案,所以我一直在使用我的魔力,直到更好的东西出现。

As I mentioned, I'm using a mac for development. I was compressing the files with "zip", which is apparently a no-no. This is true despite the fact that both "unzip" and "gunzip" handle the files fine. You must use gzip to end up with an archive that the Android's NDK's libz can handle. As for the question "How can you debug this sort of thing", I still don't have a good answer so Im stuck using my magical powers until something better comes along.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文