File: zpipe.cpp

package info (click to toggle)
libhpptools 1.1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 592 kB
  • sloc: cpp: 9,886; makefile: 9
file content (34 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include "zstr.hpp"

int main()
{
    //
    // Create explicit zstr::streambuf feeding off the streambuf of std::cin.
    // This syntax allows for setting the buffer size and the auto-detect option.
    //
    zstr::istreambuf zsbuf(std::cin.rdbuf(), 1<<16, true);
    //
    // Create an std::istream wrapper for the zstr::streambuf.
    // NOTE: A zstr::istream constructed with a zstr::streambuf parameter would decompress twice.
    //
    std::istream is(&zsbuf);
    //
    // Turn on error reporting (otherwise, zstream exceptions are hidden).
    //
    is.exceptions(std::ios_base::badbit);
    //
    // Main loop
    //
    const std::streamsize buff_size = 1 << 16;
    char * buff = new char [buff_size];
    while (true)
    {
        is.read(buff, buff_size);
        std::streamsize cnt = is.gcount();
        if (cnt == 0) break;
        std::cout.write(buff, cnt);
    }
    delete [] buff;
}