| 1 | // | 
|---|---|
| 2 | // base64decode.cpp | 
| 3 | // | 
| 4 | // This sample demonstrates the Base64Decoder 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/Base64Decoder.h" | 
| 14 | #include "Poco/StreamCopier.h" | 
| 15 | #include <iostream> | 
| 16 | #include <fstream> | 
| 17 | |
| 18 | |
| 19 | using Poco::Base64Decoder; | 
| 20 | using Poco::StreamCopier; | 
| 21 | |
| 22 | |
| 23 | int 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 base64-encoded <input_file>, decode it and write the result to <output_file>"<< std::endl; | 
| 29 | return 1; | 
| 30 | } | 
| 31 | |
| 32 | std::ifstream istr(argv[1]); | 
| 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 | Base64Decoder decoder(istr); | 
| 47 | StreamCopier::copyStream(decoder, ostr); | 
| 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 | 
