1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
39 #include <anna/core/core.hpp>
41 #include <anna/io/BinaryReader.hpp>
45 int main (int argc, const char** argv)
47 CommandLine& commandLine (CommandLine::instantiate ());
48 io::BinaryReader reader (32 * 1024);
49 DataBlock contain (true);
50 ZBlock zcompress, zuncompress;
51 const DataBlock* block;
52 ZBlock::Mode::_v mode;
55 commandLine.add ("f", CommandLine::Argument::Mandatory, "Filename to be compressed");
56 commandLine.add ("m", CommandLine::Argument::Mandatory, "Mode (d,s,c)");
58 commandLine.initialize (argv, argc);
59 commandLine.verify ();
61 // Lee el contenido del fichero indicado y lo guarda en el buffer
62 reader.open (commandLine.getValue ("f"));
63 while ((block = reader.fetch ()) != NULL)
66 cout << "Contain: \t" << functions::asString (contain, 24) << endl << endl;
68 std::string hexString;
69 cout << "Contain (asHexString): " << (hexString = functions::asHexString (contain)) << endl << endl;
72 functions::fromHexString (hexString, aux);
73 cout << "Contain: (fromHexString): \t" << functions::asString (aux, 24) << endl << endl;
75 const char* smode = commandLine.getValue ("m");
78 case 'd': mode = ZBlock::Mode::Default; break;
79 case 's': mode = ZBlock::Mode::BestSpeed; break;
80 case 'c': mode = ZBlock::Mode::BestCompression; break;
83 cout << "Original: " << contain.getSize () << " bytes";
84 cout << functions::asString (DataBlock (contain.getData (), min (128, contain.getSize ()), false), 24) << " (and more)" << endl << endl;
86 zcompress.compress (contain, mode);
87 cout << "Compress: " << zcompress.getSize () << " bytes";
88 cout << functions::asString (DataBlock (zcompress.getData (), min (128, zcompress.getSize ()), false), 24) << " (and more)" << endl << endl;
90 const DataBlock& uncompress = zuncompress.uncompress (zcompress);
91 cout << "UnCompress: " << uncompress.getSize () << " bytes";
92 cout << functions::asString (DataBlock (uncompress.getData (), min (128, uncompress.getSize ()), false), 24) << " (and more)" << endl << endl;
94 catch (Exception& ex) {
95 cout << ex.asString () << endl;