3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-28 11:25:53 +00:00

gzip: istream

This commit is contained in:
Emil J. Tywoniak 2024-12-20 12:35:57 +01:00
parent 7c6d2b44a5
commit 6c55df3467
7 changed files with 225 additions and 138 deletions

View file

@ -1,13 +1,11 @@
#include "kernel/yosys_common.h"
#include <string>
#include <unistd.h>
#include <stdarg.h>
#include "kernel/yosys_common.h"
#ifndef YOSYS_IO_H
#define YOSYS_IO_H
#ifdef YOSYS_ENABLE_ZLIB
#include <zlib.h>
#endif
YOSYS_NAMESPACE_BEGIN
inline std::string vstringf(const char *fmt, va_list ap)
@ -67,34 +65,6 @@ inline std::string stringf(const char *fmt, ...)
return string;
}
#ifdef YOSYS_ENABLE_ZLIB
/*
An output stream that uses a stringbuf to buffer data internally,
using zlib to write gzip-compressed data every time the stream is flushed.
*/
class gzip_ostream : public std::ostream {
public:
gzip_ostream();
bool open(const std::string &filename);
private:
class gzip_streambuf : public std::stringbuf {
public:
gzip_streambuf();
bool open(const std::string &filename);
virtual int sync() override;
virtual ~gzip_streambuf();
private:
static const int buffer_size = 4096; // Size of the internal buffer
char buffer[buffer_size]; // Internal buffer for compressed data
gzFile gzf = nullptr; // Handle to the gzip file
};
gzip_streambuf outbuf; // The stream buffer instance
};
#endif // YOSYS_ENABLE_ZLIB
std::istream* uncompressed(std::ifstream* f, const std::string filename);
YOSYS_NAMESPACE_END
#endif // YOSYS_IO_H