Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class Container>
- Container readcompressfile(string ifileloc) {
- ifstream ifile(ifileloc);
- if (!ifile) {
- throw runtime_error("Could not open " + ifileloc + " for reading");
- }
- noskipws(ifile);
- return Container(istream_iterator<uint8_t>(ifile), istream_iterator<uint8_t>());
- }
- void decompressfile(string loc) {
- vector<uint8_t> vecbytes(readcompressfile<vector<uint8_t>>(ifilelocation)); // Here is where I'm using the above function
- vector<uint8_t>::iterator iter = vecbytes.begin();
- uint8_t ctr = 0xFF;
- bitset<8> b2 = 0;
- string code = "";
- for (; iter != vecbytes.end(); ++iter) {
- b2 = ctr & *iter;
- for (int i = 7; i >= 0; i--) {
- code += to_string(b2[i]);
- }
- }
- decodetext(code, loc);
- }
- //Reads bits and outputs string
- void decodetext(string codetext, string ofileloc) {
- string code = "";
- string text = "";
- char lett;
- for each (char ct in codetext) {
- code += ct;
- lett = returncharmap(code);
- if (lett != NULL) {
- text += lett;
- code = "";
- }
- }
- ofstream ofile(ofileloc);
- ofile << text;
- ofile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement