Skip to content
/ zstream Public

A standard-library-compatible implementation of a stream that compresses or decompresses with zlib.

License

Notifications You must be signed in to change notification settings

ngober/zstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pre-commit.ci status Run Tests Coverage Status

zstream

A standard-library-compatible implementation of a stream that compresses or decompresses with zlib.

Compile with

g++ --std=c++11 zstream.cc -lz

Run with

./a.out < foo.txt > foo.gz

These stream buffers can be used with any type that supports operator>> and/or operator<<.

Example: Compress the first N fibonacci numbers and capture the result as a std::string.

std::ostringstream ostrstr{};
def_streambuf osb{ostrstr};
std::ostream os{&osb};

constexpr std::size_t N = 1 << 8;
long curr = 0, next = 1;

for (std::size_t i = 0; i < N; ++i)
{
    os << curr;
    curr = std::exchange(next, next+curr);
}
os << std::flush;

std::string result = ostrstr.str();

About

A standard-library-compatible implementation of a stream that compresses or decompresses with zlib.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages