diff --git a/README.md b/README.md index ef2f46c..4e50a1a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # mashzip -yet another gzip \ No newline at end of file +yet another gzip + +Example: +``` +Some long text!!!!\x01\x02\x03\x04 +``` + +```hexdump +00000000: 4d41 5348 0554 4000 0000 0000 0000 0000 MASH.T@......... +00000010: 0000 0000 3300 0000 0000 0000 0000 0000 ....3........... +00000020: 0000 0000 0000 0000 0000 0000 0005 0000 ................ +00000030: 0000 0000 0000 0404 0000 4544 0000 3000 ..........ED..0. +00000040: 4000 0000 0000 0000 0000 0000 0000 0000 @............... +00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ +00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ +00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ +00000080: 0000 0000 9e3f 4279 13c2 5692 f06e 07 .....?By..V..n. +``` \ No newline at end of file diff --git a/main.cpp b/main.cpp index 2a4bce9..0752d33 100644 --- a/main.cpp +++ b/main.cpp @@ -193,56 +193,56 @@ using namespace std; //// Huffman coding algorithm int main(int argc, char **argv) { -// buildHuffmanTree(cin); - // 10111010 11110101 - stringstream ss("\xba\xf5"); - ibitstream ibs(ss); +// // buildHuffmanTree(cin); +// // 10111010 11110101 +// stringstream ss("\xba\xf5"); +// ibitstream ibs(ss); - // 10111010 11110101 - // ^^ - int a = ibs.getbits(2); - cout << bitset<2>(a) << endl; +// // 10111010 11110101 +// // ^^ +// int a = ibs.getbits(2); +// cout << bitset<2>(a) << endl; - // 10111010 11110101 - // ^^^^ - int b = ibs.getbits(4); - cout << bitset<4>(b) << endl; +// // 10111010 11110101 +// // ^^^^ +// int b = ibs.getbits(4); +// cout << bitset<4>(b) << endl; - // 10111010 11110101 - // ^^ ^^^^^^^ - b = ibs.getbits(9); - cout << bitset<9>(b) << endl; +// // 10111010 11110101 +// // ^^ ^^^^^^^ +// b = ibs.getbits(9); +// cout << bitset<9>(b) << endl; - // 10111010 11110101 - // ^ + overflow - try { - b = ibs.getbits(10); - cout << b << endl; - } catch (std::runtime_error &e) { - cout << "Got runtime error: " << e.what() << endl; - } +// // 10111010 11110101 +// // ^ + overflow +// try { +// b = ibs.getbits(10); +// cout << b << endl; +// } catch (std::runtime_error &e) { +// cout << "Got runtime error: " << e.what() << endl; +// } - ostringstream so("bits: "); - obitstream obs(so); +// ostringstream so("bits: "); +// obitstream obs(so); - obs.writebits(0xf, 3); - cout << "After 3 bits: " << so.str() << endl; - // cache here: 00000111 +// obs.writebits(0xf, 3); +// cout << "After 3 bits: " << so.str() << endl; +// // cache here: 00000111 - obs.writebits(0xf5, 7); - // here: Flush: 10101111 - cout << "After 7 bits: " << so.str() << endl; - obs.flush(); - // here: Flush: 00000011 - cout << "After flush: " << so.str() << endl; +// obs.writebits(0xf5, 7); +// // here: Flush: 10101111 +// cout << "After 7 bits: " << so.str() << endl; +// obs.flush(); +// // here: Flush: 00000011 +// cout << "After flush: " << so.str() << endl; - obs.writebits(0xbeef, 16); - cout << "After 0xbeef: " << so.str() << endl; - obs.flush(); - // here: Flush: 0xEFBE - reversed! - cout << "After flush: " << so.str() << endl; +// obs.writebits(0xbeef, 16); +// cout << "After 0xbeef: " << so.str() << endl; +// obs.flush(); +// // here: Flush: 0xEFBE - reversed! +// cout << "After flush: " << so.str() << endl; string s = "Some long text!!!!\x01\x02\x03\x04"; @@ -252,10 +252,10 @@ int main(int argc, char **argv) HuffmanTable ht(ss1); uint8_t *header = ht.to_header(); - for (size_t i = 0; i < 128; i++) - { - cout << "Code for " << 2 * i << " and " << 2 * i + 1 << ": " << bitset<8>(header[i]) << endl; - } + // for (size_t i = 0; i < 128; i++) + // { + // cout << "Code for " << 2 * i << " and " << 2 * i + 1 << ": " << bitset<8>(header[i]) << endl; + // } ostringstream test; @@ -272,7 +272,7 @@ int main(int argc, char **argv) } some_stream.flush(); - std::cout << "Coding result: " << test.str() << endl; + std::cout << test.str(); return 0; } \ No newline at end of file