lz4.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // ErrInvalidFrame is returned when reading an invalid LZ4 archive.
  25. ErrInvalidFrame _error = "lz4: bad magic number"
  26. // ErrUnsupportedSeek is returned when attempting to Seek any way but forward from the current position.
  27. ErrUnsupportedSeek _error = "lz4: can only seek forward from io.SeekCurrent"
  28. // ErrInternalUnhandledState is an internal error.
  29. ErrInternalUnhandledState _error = "lz4: unhandled state"
  30. // ErrInvalidHeaderChecksum is returned when reading a frame.
  31. ErrInvalidHeaderChecksum _error = "lz4: invalid header checksum"
  32. // ErrInvalidBlockChecksum is returned when reading a frame.
  33. ErrInvalidBlockChecksum _error = "lz4: invalid block checksum"
  34. // ErrInvalidFrameChecksum is returned when reading a frame.
  35. ErrInvalidFrameChecksum _error = "lz4: invalid frame checksum"
  36. // ErrOptionInvalidCompressionLevel is returned when the supplied compression level is invalid.
  37. ErrOptionInvalidCompressionLevel _error = "lz4: invalid compression level"
  38. // ErrOptionClosedOrError is returned when an option is applied to a closed or in error object.
  39. ErrOptionClosedOrError _error = "lz4: cannot apply options on closed or in error object"
  40. // ErrOptionInvalidBlockSize is returned when
  41. ErrOptionInvalidBlockSize _error = "lz4: invalid block size"
  42. // ErrOptionNotApplicable is returned when trying to apply an option to an object not supporting it.
  43. ErrOptionNotApplicable _error = "lz4: option not applicable"
  44. )