Giter Site home page Giter Site logo

zstr's Introduction

zstr: A C++ ZLib wrapper

This C++ header-only library enables the use of C++ standard iostreams to access ZLib-compressed streams.

For input access (decompression), the compression format is auto-detected, and multiple concatenated compressed streams are decompressed seamlessly.

For output access (compression), the only parameter exposed by this API is the compression level.

Alternatives to this library include:

  • The original ZLib, through its C API. This does not interact nicely with C++ iostreams.
  • The GZStream library. This library does not auto-detect input compression, and it cannot wrap streams (only files).
  • The Boost IOStreams library. The library does not auto-detect input compression (by default, though that can be easily implemented with filters), and more importantly, it is not a header-only Boost library.

For an example usage, see examples/ztxtpipe.cpp and examples/zc.cpp.

Input Auto-detection

For input access, the library seamlessly auto-detects whether the source stream is compressed or not. The following compressed streams are detected:

  • GZip header, when stream starts with 1F 8B. See GZip format.
  • ZLib header, when stream starts with 78 01, 78 9C, and 78 DA. See answer here.

If none of these formats are detected, the library assumes the input is not compressed, and it produces a plain copy of the source stream.

Classes

The package provides 6 classes for accessing ZLib streams:

  • zstr::istreambuf is the core decompression class. This is constructed from an existing std::streambuf that contains source data. The zstr::istreambuf constructor accepts explicit settings for the internal buffer size (default: 1 MB) and the auto-detection option (default: on). ZLib errors cause exceptions to be thrown.
  • zstr::ostreambuf is the core compression class. This is constructed from an existing std::streambuf that contains sink data. The zstr::ostreambuf constructor accepts explicit settings for the internal buffer size (default: 1 MB) and the compression option (default: ZLib default). ZLib errors cause exceptions to be thrown.
  • zstr::istream is a wrapper for a zstr::istreambuf that accesses an external std::streambuf. It can be constructed from an existing std::istream (such as std::cin) or std::streambuf.
  • zstr::ostream is a wrapper for a zstr::ostreambuf that accesses an external std::streambuf. It can be constructed from an existing std::ostream (such as std::cout) or std::streambuf.
  • zstr::ifstream is a wrapper for a zstr::istreambuf that accesses an internal std::ifstream. This can be used to open a file and read decompressed data from it.
  • zstr::ofstream is a wrapper for a zstr::ostreambuf that accesses an internal std::ofstream. This can be used to open a file and write compressed data to it.

All stream objects the badbit of the expection mask is turned on in order to propagate exceptions.

zstr's People

Contributors

mateidavid avatar ajmacd avatar

Watchers

Ani Betts avatar Paul Hammond avatar Taylor Singletary avatar Johnny Rodgers avatar Matt Hawkins avatar Rob Ellis avatar Wade Simmons avatar Adam Spooner avatar Merci Victoria Grace avatar  avatar Todd Kloots avatar Jamie Scheinblum avatar Jim Whimpey avatar paragshah avatar Derek Smith avatar Pavel Macek avatar Saurabh Sahni avatar Matt Crocker avatar Renaud Bourassa avatar Erik Hope avatar Myles Grant avatar Ryan Greenberg avatar Edmund Salvacion avatar Yuichi avatar Keith Adams avatar  avatar  avatar Rands avatar David McCreath avatar Dave Fearon avatar Roland Schemers avatar Saroj Yadav avatar Chris DeSalvo avatar Mithlesh Kumar Jha avatar Marcel Weekes avatar sven chen avatar Brett Pemberton avatar Trish Ang avatar Andrei Patru avatar Josh Wills avatar  avatar Zachary Forrest y Salazar avatar Boris de Souza avatar John Kavanagh avatar Mioi Hanaoka avatar Brendan Moore avatar Justin Fu avatar Michael Montazeri avatar William Kimeria avatar shiqi avatar Vishal avatar Jahanzeb Sherwani avatar Anthony Lee avatar James Cloos avatar Justin Rushing avatar Steven Sanchez avatar Izzy Johnston avatar Matt Wahl avatar  avatar Moishe Lettvin avatar Ibrahim Madha avatar Brad Stronger avatar Simone Soldateschi avatar  avatar Faraz Khan avatar Raphael Palefsky-Smith avatar  avatar Scott Sandler avatar  avatar Sushil Rangarajan avatar Nihit avatar Kaustubh Deshmukh avatar Albert avatar Jonathan Yung avatar deepak avatar Raja Jamwal avatar  avatar Kevin Marshall avatar Mary avatar  avatar Karine Sully avatar Chris Peterson avatar zmagg avatar Leo avatar Radha avatar Chintan avatar Alan Lam avatar Doug Lam avatar Tolga AKIN avatar Steven Cary avatar Adam Speakman avatar Cory Bujnowicz avatar Finn Ellis avatar Lydia Wagner avatar Danil Glinenko avatar SJC avatar Jess Kirkpatrick avatar  avatar Chung-Yi Cho avatar Tosin Afolabi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.