Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. template<class Container>
  2. Container readcompressfile(string ifileloc) {
  3. ifstream ifile(ifileloc);
  4.  
  5. if (!ifile) {
  6. throw runtime_error("Could not open " + ifileloc + " for reading");
  7. }
  8.  
  9. noskipws(ifile);
  10.  
  11. return Container(istream_iterator<uint8_t>(ifile), istream_iterator<uint8_t>());
  12. }
  13.  
  14. void decompressfile(string loc) {
  15. vector<uint8_t> vecbytes(readcompressfile<vector<uint8_t>>(ifilelocation)); // Here is where I'm using the above function
  16.  
  17. vector<uint8_t>::iterator iter = vecbytes.begin();
  18.  
  19. uint8_t ctr = 0xFF;
  20. bitset<8> b2 = 0;
  21. string code = "";
  22.  
  23. for (; iter != vecbytes.end(); ++iter) {
  24. b2 = ctr & *iter;
  25.  
  26. for (int i = 7; i >= 0; i--) {
  27. code += to_string(b2[i]);
  28. }
  29. }
  30.  
  31. decodetext(code, loc);
  32. }
  33.  
  34. //Reads bits and outputs string
  35. void decodetext(string codetext, string ofileloc) {
  36. string code = "";
  37. string text = "";
  38. char lett;
  39.  
  40. for each (char ct in codetext) {
  41. code += ct;
  42. lett = returncharmap(code);
  43. if (lett != NULL) {
  44. text += lett;
  45. code = "";
  46. }
  47. }
  48.  
  49. ofstream ofile(ofileloc);
  50. ofile << text;
  51. ofile.close();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement