1//
2// deflate.cpp
3//
4// This sample demonstrates the DeflatingOutputStream and StreamCopier classes.
5//
6// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#include "Poco/DeflatingStream.h"
14#include "Poco/StreamCopier.h"
15#include <iostream>
16#include <fstream>
17
18
19using Poco::DeflatingOutputStream;
20using Poco::StreamCopier;
21
22
23int main(int argc, char** argv)
24{
25 if (argc != 3)
26 {
27 std::cout << "usage: " << argv[0] << ": <input_file> <output_file>" << std::endl
28 << " read <input_file>, deflate (compress) it and write the result to <output_file>" << std::endl;
29 return 1;
30 }
31
32 std::ifstream istr(argv[1], std::ios::binary);
33 if (!istr)
34 {
35 std::cerr << "cannot open input file: " << argv[1] << std::endl;
36 return 2;
37 }
38
39 std::ofstream ostr(argv[2], std::ios::binary);
40 if (!ostr)
41 {
42 std::cerr << "cannot open output file: " << argv[2] << std::endl;
43 return 3;
44 }
45
46 DeflatingOutputStream deflater(ostr);
47 StreamCopier::copyStream(istr, deflater);
48
49 if (!ostr)
50 {
51 std::cerr << "error writing output file: " << argv[2] << std::endl;
52 return 4;
53 }
54
55 return 0;
56}
57