lz4.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package lz4
  2. const (
  3. frameMagic uint32 = 0x184D2204
  4. frameSkipMagic uint32 = 0x184D2A50
  5. // The following constants are used to setup the compression algorithm.
  6. minMatch = 4 // the minimum size of the match sequence size (4 bytes)
  7. winSizeLog = 16 // LZ4 64Kb window size limit
  8. winSize = 1 << winSizeLog
  9. winMask = winSize - 1 // 64Kb window of previous data for dependent blocks
  10. // hashLog determines the size of the hash table used to quickly find a previous match position.
  11. // Its value influences the compression speed and memory usage, the lower the faster,
  12. // but at the expense of the compression ratio.
  13. // 16 seems to be the best compromise for fast compression.
  14. hashLog = 16
  15. htSize = 1 << hashLog
  16. mfLimit = 10 + minMatch // The last match cannot start within the last 14 bytes.
  17. )
  18. type _error string
  19. func (e _error) Error() string { return string(e) }
  20. const (
  21. // ErrInvalidSourceShortBuffer is returned by UncompressBlock or CompressBLock when a compressed
  22. // block is corrupted or the destination buffer is not large enough for the uncompressed data.
  23. ErrInvalidSourceShortBuffer _error = "lz4: invalid source or destination buffer too short"
  24. // ErrClosed is returned when calling Write/Read or Close on an already closed Writer/Reader.
  25. ErrClosed _error = "lz4: closed Writer"
  26. // ErrInvalid is returned when reading an invalid LZ4 archive.
  27. ErrInvalid _error = "lz4: bad magic number"
  28. // ErrBlockDependency is returned when attempting to decompress an archive created with block dependency.
  29. ErrBlockDependency _error = "lz4: block dependency not supported"
  30. // ErrUnsupportedSeek is returned when attempting to Seek any way but forward from the current position.
  31. ErrUnsupportedSeek _error = "lz4: can only seek forward from io.SeekCurrent"
  32. // ErrInternalUnhandledState is an internal error.
  33. ErrInternalUnhandledState _error = "lz4: unhandled state"
  34. // ErrInvalidHeaderChecksum
  35. ErrInvalidHeaderChecksum _error = "lz4: invalid header checksum"
  36. // ErrInvalidBlockChecksum
  37. ErrInvalidBlockChecksum _error = "lz4: invalid block checksum"
  38. // ErrInvalidFrameChecksum
  39. ErrInvalidFrameChecksum _error = "lz4: invalid frame checksum"
  40. )