| 905 | } |
| 906 | |
| 907 | plen_t chunk_reader::read(void *data, plen_t len) |
| 908 | { |
| 909 | ASSERT(data); |
| 910 | if (pkg->aborted) |
| 911 | return 0; |
| 912 | |
| 913 | #ifdef USE_ZLIB |
| 914 | if (!len) |
| 915 | return 0; |
| 916 | if (eof) |
| 917 | return 0; |
| 918 | |
| 919 | zs.next_out = (Bytef*)data; |
| 920 | zs.avail_out = len; |
| 921 | while (zs.avail_out) |
| 922 | { |
| 923 | if (!zs.avail_in) |
| 924 | { |
| 925 | zs.next_in = z_buffer; |
| 926 | zs.avail_in = raw_read(z_buffer, sizeof(z_buffer)); |
| 927 | if (!zs.avail_in) |
| 928 | corrupted("save file corrupted -- block truncated"); |
| 929 | } |
| 930 | int res = inflate(&zs, Z_NO_FLUSH); |
| 931 | if (res == Z_STREAM_END) |
| 932 | { |
| 933 | eof = true; |
| 934 | return zs.next_out - (Bytef*)data; |
| 935 | } |
| 936 | if (res != Z_OK) |
| 937 | corrupted("save file decompression failed: %s", zs.msg); |
| 938 | } |
| 939 | return zs.next_out - (Bytef*)data; |
| 940 | #else |
| 941 | return raw_read(data, len); |
| 942 | #endif |
| 943 | } |
| 944 | |
| 945 | void chunk_reader::read_all(vector<char> &data) |
| 946 | { |
no test coverage detected