You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
515 B

11 years ago
11 years ago
11 years ago
  1. package storage
  2. import (
  3. "fmt"
  4. "hash/crc32"
  5. "github.com/chrislusf/seaweedfs/go/util"
  6. )
  7. var table = crc32.MakeTable(crc32.Castagnoli)
  8. type CRC uint32
  9. func NewCRC(b []byte) CRC {
  10. return CRC(0).Update(b)
  11. }
  12. func (c CRC) Update(b []byte) CRC {
  13. return CRC(crc32.Update(uint32(c), table, b))
  14. }
  15. func (c CRC) Value() uint32 {
  16. return uint32(c>>15|c<<17) + 0xa282ead8
  17. }
  18. func (n *Needle) Etag() string {
  19. bits := make([]byte, 4)
  20. util.Uint32toBytes(bits, uint32(n.Checksum))
  21. return fmt.Sprintf("\"%x\"", bits)
  22. }