Guest User

Untitled

a guest
Oct 21st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import os
  2. import struct
  3. import zlib
  4. from _block import compress, decompress, LZ4BlockError
  5.  
  6. FOOTER_STRUCTURE = '4I4s'
  7. FOOTER_SIZE = struct.calcsize(FOOTER_STRUCTURE)
  8.  
  9. inPath = '.\\pack'
  10. filesIn = []
  11. for (dirpath, dirnames, filenames) in os.walk(inPath):
  12.     filesIn.extend(filenames)
  13.     break
  14.  
  15. for fileIn in filesIn:
  16.     infile = inPath + '\\' + fileIn
  17.     outPath = '.\\temp\\'
  18.     with open(infile, 'rb') as f, open(outPath + fileIn, 'wb') as out:
  19.         unpacked = os.stat(infile).st_size
  20.         result = compress(f.read(), mode='high_compression', compression=12, store_size=False)
  21.         packed = len(result)
  22.         crc = zlib.crc32(result) & 0xFFFFFFFF
  23.         ptype = 2
  24.         marker = 'DVPL'
  25.         data = struct.pack(FOOTER_STRUCTURE, unpacked, packed, crc, ptype, marker)
  26.         result += data
  27.         out.write(result)
  28.         out.close()
  29.         f.close()
  30. if filesIn == []:
  31.     print('! No files found for pack to DVPL !')
  32. else:
  33.     print('Files packed')
Advertisement
Add Comment
Please, Sign In to add comment