开发者

Android NDK zlib returning Z_DATA_ERROR for valid zip info

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开发者_StackOverflow can I do to debug this?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜