- gzFile gf = stream->param;\r
- int err;\r
- ret = gzread(gf, ptr, bytes);\r
- err = gzerror2(gf);\r
- if (ret > 0 && (err == Z_DATA_ERROR || err == Z_STREAM_END))\r
- /* we must reset stream pointer or else next seek/read fails */\r
- gzrewind(gf);\r
+ struct zip_file *z = stream->file;\r
+\r
+ if (z->entry->compression_method == 0) {\r
+ int ret = fread(ptr, 1, bytes, z->zip->fp);\r
+ z->pos += ret;\r
+ return ret;\r
+ }\r
+\r
+ z->stream.next_out = ptr;\r
+ z->stream.avail_out = bytes;\r
+ while (z->stream.avail_out != 0) {\r
+ if (z->stream.avail_in == 0) {\r
+ z->stream.avail_in = fread(z->inbuf, 1, sizeof(z->inbuf), z->zip->fp);\r
+ if (z->stream.avail_in == 0)\r
+ break;\r
+ z->stream.next_in = z->inbuf;\r
+ }\r
+ ret = inflate(&z->stream, Z_NO_FLUSH);\r
+ if (ret == Z_STREAM_END)\r
+ break;\r
+ if (ret != Z_OK) {\r
+ elprintf(EL_STATUS, "zip: inflate: %d", ret);\r
+ return 0;\r
+ }\r
+ }\r
+ z->pos += bytes - z->stream.avail_out;\r
+ return bytes - z->stream.avail_out;\r