1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
5 $Id: b64.cxx,v 1.2 2005/02/23 10:26:14 tat Exp $
6 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
17 * Usage: b64 [-ed] [in_file [out_file]]
19 * Base64 encodes or decodes in_file (or standard input) and writes
20 * output to out_file (or standard output)
25 #include <mimetic/mimetic.h>
28 using namespace mimetic;
32 cout << "b64 [-ed] [in_file [out_file]]" << endl;
36 void die_if(bool b, const string& s)
45 int main(int argc, char** argv)
47 std::ios_base::sync_with_stdio(false);
64 fin.open(argv[2], ios::in);
65 die_if(!fin.is_open(), string("unable to open file ")+argv[2]);
69 fout.open(argv[3], ios::out);
70 die_if(!fout.is_open(), string("unable to open file ")+argv[3]);
72 istream is( fin.is_open() ? &fin : cin.rdbuf());
73 ostream os( fout.is_open() ? &fout : cout.rdbuf());
74 istreambuf_iterator<char> ibeg(is), iend;
75 ostreambuf_iterator<char> out(os);
78 code(ibeg, iend, b64, out);
81 code(ibeg, iend, b64, out);