1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/core/core.hpp>
13 #include <anna/io/BinaryReader.hpp>
17 int main (int argc, const char** argv)
19 CommandLine& commandLine (CommandLine::instantiate ());
20 io::BinaryReader reader (32 * 1024);
21 DataBlock contain (true);
22 ZBlock zcompress, zuncompress;
23 const DataBlock* block;
24 ZBlock::Mode::_v mode;
27 commandLine.add ("f", CommandLine::Argument::Mandatory, "Filename to be compressed");
28 commandLine.add ("m", CommandLine::Argument::Mandatory, "Mode (d,s,c)");
30 commandLine.initialize (argv, argc);
31 commandLine.verify ();
33 // Lee el contenido del fichero indicado y lo guarda en el buffer
34 reader.open (commandLine.getValue ("f"));
35 while ((block = reader.fetch ()) != NULL)
38 cout << "Contain: \t" << functions::asString (contain, 24) << endl << endl;
40 std::string hexString;
41 cout << "Contain (asHexString): " << (hexString = functions::asHexString (contain)) << endl << endl;
44 functions::fromHexString (hexString, aux);
45 cout << "Contain: (fromHexString): \t" << functions::asString (aux, 24) << endl << endl;
47 const char* smode = commandLine.getValue ("m");
50 case 'd': mode = ZBlock::Mode::Default; break;
51 case 's': mode = ZBlock::Mode::BestSpeed; break;
52 case 'c': mode = ZBlock::Mode::BestCompression; break;
55 cout << "Original: " << contain.getSize () << " bytes";
56 cout << functions::asString (DataBlock (contain.getData (), min (128, contain.getSize ()), false), 24) << " (and more)" << endl << endl;
58 zcompress.compress (contain, mode);
59 cout << "Compress: " << zcompress.getSize () << " bytes";
60 cout << functions::asString (DataBlock (zcompress.getData (), min (128, zcompress.getSize ()), false), 24) << " (and more)" << endl << endl;
62 const DataBlock& uncompress = zuncompress.uncompress (zcompress);
63 cout << "UnCompress: " << uncompress.getSize () << " bytes";
64 cout << functions::asString (DataBlock (uncompress.getData (), min (128, uncompress.getSize ()), false), 24) << " (and more)" << endl << endl;
66 catch (Exception& ex) {
67 cout << ex.asString () << endl;