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.

41 lines
662 B

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