From cdca53e4deabcb8534969143055b7cf450c2be00 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Thu, 19 Dec 2024 20:49:17 +0100 Subject: [PATCH] gzipping istream --- kernel/gzip.cc | 9 +++++---- kernel/gzip.h | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/gzip.cc b/kernel/gzip.cc index d69d5764edb..52c9e413a99 100644 --- a/kernel/gzip.cc +++ b/kernel/gzip.cc @@ -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 diff --git a/kernel/gzip.h b/kernel/gzip.h index 61558590142..a00ac66a6b5 100644 --- a/kernel/gzip.h +++ b/kernel/gzip.h @@ -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