Skip to content

Commit

Permalink
gzipping istream
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Dec 19, 2024
1 parent 5dbd4e8 commit cdca53e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions kernel/gzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ std::istream* uncompressed(std::ifstream* f, const std::string filename) {
if (magic[2] != 8)
log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
filename.c_str(), unsigned(magic[2]));
delete f;
std::stringstream *df = new std::stringstream();
decompress_gzip(filename, *df);
return df;
delete f;
// std::stringstream *df = new std::stringstream();
// decompress_gzip(filename, *df);
gzip_istream* s = new gzip_istream();
return s->open(filename.c_str()) ? s : nullptr;
#else
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
#endif // YOSYS_ENABLE_ZLIB
Expand Down
9 changes: 7 additions & 2 deletions kernel/gzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ class gzip_istream final : public std::istream {
if (bytes_read <= 0) {
// An error occurred during reading
int err;
if (Zlib::gzeof(gzf))
return traits_type::eof();

const char* error_msg = Zlib::gzerror(gzf, &err);
if (err != Z_STREAM_END)
if (err != Z_OK)
log_error("%s", error_msg);
return traits_type::eof();
else
log_error("Decompression logic failure: "\
"read <=0 bytes but neither EOF nor error\n");
}

// Reset buffer pointers
Expand Down

0 comments on commit cdca53e

Please sign in to comment.