helpers.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import lz4.frame as lz4frame
  2. def get_frame_info_check(compressed_data,
  3. source_size,
  4. store_size,
  5. block_size,
  6. block_linked,
  7. content_checksum,
  8. block_checksum):
  9. frame_info = lz4frame.get_frame_info(compressed_data)
  10. assert frame_info["content_checksum"] == content_checksum
  11. assert frame_info["block_checksum"] == block_checksum
  12. assert frame_info["skippable"] is False
  13. if store_size is True:
  14. assert frame_info["content_size"] == source_size
  15. else:
  16. assert frame_info["content_size"] == 0
  17. if source_size > frame_info['block_size']:
  18. # More than a single block
  19. assert frame_info["block_linked"] == block_linked
  20. if block_size == lz4frame.BLOCKSIZE_DEFAULT:
  21. assert frame_info["block_size_id"] == lz4frame.BLOCKSIZE_MAX64KB
  22. else:
  23. assert frame_info["block_size_id"] == block_size
  24. def get_chunked(data, nchunks):
  25. size = len(data)
  26. # stride = int(math.ceil(float(size)/nchunks)) # no // on py 2.6
  27. stride = size // nchunks
  28. start = 0
  29. end = start + stride
  30. while end < size:
  31. yield data[start:end]
  32. start += stride
  33. end += stride
  34. yield data[start:]