SHARE
TWEET

Memory File helper for zlib compress

a guest Feb 20th, 2013 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct MemFile
  2. {
  3.         std::vector<unsigned char> bytes;
  4.         std::vector<unsigned char> zip;
  5.         void clear() { bytes.clear(); zip.clear(); }
  6.         void pack()
  7.         {
  8.                 int zip_size = bytes.size()*1.2;
  9.                 if (zip_size < 1000)
  10.                         zip_size = 1000;
  11.                 zip.resize(zip_size);
  12.                 unsigned int destLen;
  13.                 compress(&zip[0], (unsigned int*)&destLen, &bytes[0], (unsigned int)bytes.size());
  14.                 zip.resize(destLen);
  15.         }
  16. };
  17.  
  18. int fwrite(void *buffer, int size, int count, MemFile*f)
  19. {
  20.         int last_size = f->bytes.size();
  21.         f->bytes.resize(last_size + size * count);
  22.         memcpy(&(f->bytes[last_size]), buffer, size * count);
  23.         return size * count;
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top