You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting a logic error, "Error inflating stream", when reading larger arrays from an npz archive. After a lot of debugging I found out that by increasing the size of CHUNK in zip.cpp so that the file could be read in a single pass everything worked as expected.
Here is the solution I came up with. Basically replacing the npy_inflate() call in the read_file function in npz.cpp with a single pass inflation. Everything is anyway in memory all the time and there is no need to split the inflation step up into chunks.
//Use one step inflation, we anyway need to hold everything in memory at some point
std::vector<std::uint8_t> compressed_bytes(uncompressed_bytes);
uncompressed_bytes.resize(entry.uncompressed_size);
//Initialize miniz
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
const int WINDOW_BITS = -15;
auto ret = inflateInit2(&strm, WINDOW_BITS);
if (ret != Z_OK)
{
throw std::logic_error("Unable to initialize inflate algorithm");
}
//Inflate in one step
strm.next_in = &compressed_bytes[0];
strm.avail_in = compressed_bytes.size();
strm.next_out = &uncompressed_bytes[0];
strm.avail_out = uncompressed_bytes.size();
ret = inflate(&strm, Z_FINISH);
if (ret != Z_STREAM_END) {
std::cerr<<strm.msg<<std::endl;
(void)inflateEnd(&strm);
throw std::logic_error("Error inflating stream");
}
(void)inflateEnd(&strm);
The text was updated successfully, but these errors were encountered:
I've not seen this issue in testing, but I'll see if I can reproduce it. That said, the solution seems fine. If it checks out on my end, I'll make the change.
I am getting a logic error, "Error inflating stream", when reading larger arrays from an npz archive. After a lot of debugging I found out that by increasing the size of CHUNK in zip.cpp so that the file could be read in a single pass everything worked as expected.
Here is the solution I came up with. Basically replacing the npy_inflate() call in the read_file function in npz.cpp with a single pass inflation. Everything is anyway in memory all the time and there is no need to split the inflation step up into chunks.
The text was updated successfully, but these errors were encountered: