Skip to content

Commit

Permalink
Merge pull request #4024 from dmitry-ganyushin/campaign-bug
Browse files Browse the repository at this point in the history
Campaign files uncompression fix
  • Loading branch information
dmitry-ganyushin committed Feb 2, 2024
2 parents 2ca670d + f6a1691 commit 87fe33e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions source/adios2/engine/campaign/CampaignData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ void ReadCampaignData(sqlite3 *db, CampaignData &cd)
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
is an error reading or writing the files.
http://www.zlib.net/zlib_how.html */
int inflateToFile(const unsigned char *source, const size_t blobsize, std::ofstream *dest)
{
constexpr size_t CHUNK = 16777216;
Expand All @@ -190,10 +191,13 @@ int inflateToFile(const unsigned char *source, const size_t blobsize, std::ofstr

/* decompress until deflate stream ends or end of file */
unsigned char *p = const_cast<unsigned char *>(source);
uInt pos = 0;
do
{
strm.avail_in = (uInt)(blobsize > CHUNK ? CHUNK : blobsize);
strm.next_in = p;
uInt CHUNK_SIZE = static_cast<uInt>(blobsize > CHUNK ? CHUNK : blobsize);
strm.avail_in = CHUNK_SIZE;

strm.next_in = p + pos;

/* run inflate() on input until output buffer not full */
do
Expand All @@ -213,9 +217,14 @@ int inflateToFile(const unsigned char *source, const size_t blobsize, std::ofstr
}
have = CHUNK - strm.avail_out;
dest->write(reinterpret_cast<char *>(out.data()), have);
if (dest->bad())
{
helper::Throw<std::runtime_error>("Core", "Campaign", "Inflate",
"error writing file ");
}

} while (strm.avail_out == 0);

pos += CHUNK_SIZE;
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);

Expand Down Expand Up @@ -310,12 +319,10 @@ void SaveToFile(sqlite3 *db, const std::string &path, const CampaignBPFile &bpfi
int iBlobsize = sqlite3_column_bytes(statement, 0);
const void *p = sqlite3_column_blob(statement, 0);

/*std::cout << "-- Retrieved from DB data of " << bpfile.name
<< " size = " << iBlobsize
std::cout << "-- Retrieved from DB data of " << bpfile.name << " size = " << iBlobsize
<< " compressed = " << bpfile.compressed
<< " compressed size = " << bpfile.lengthCompressed
<< " original size = " << bpfile.lengthOriginal << " blob = " << p
<< "\n";*/
<< " original size = " << bpfile.lengthOriginal << " blob = " << p << "\n";

size_t blobsize = static_cast<size_t>(iBlobsize);
std::ofstream f;
Expand Down

0 comments on commit 87fe33e

Please sign in to comment.