mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
CRCWriter consistent with CRC
This commit is contained in:
parent
1444e9d275
commit
38fc200e56
|
@ -2,7 +2,6 @@ package needle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/klauspost/crc32"
|
"github.com/klauspost/crc32"
|
||||||
|
@ -35,21 +34,21 @@ func (n *Needle) Etag() string {
|
||||||
func NewCRCwriter(w io.Writer) *CRCwriter {
|
func NewCRCwriter(w io.Writer) *CRCwriter {
|
||||||
|
|
||||||
return &CRCwriter{
|
return &CRCwriter{
|
||||||
h: crc32.New(table),
|
crc: CRC(0),
|
||||||
w: w,
|
w: w,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CRCwriter struct {
|
type CRCwriter struct {
|
||||||
h hash.Hash32
|
crc CRC
|
||||||
w io.Writer
|
w io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CRCwriter) Write(p []byte) (n int, err error) {
|
func (c *CRCwriter) Write(p []byte) (n int, err error) {
|
||||||
n, err = c.w.Write(p) // with each write ...
|
n, err = c.w.Write(p) // with each write ...
|
||||||
c.h.Write(p) // ... update the hash
|
c.crc = c.crc.Update(p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CRCwriter) Sum() uint32 { return c.h.Sum32() } // final hash
|
func (c *CRCwriter) Sum() uint32 { return c.crc.Value() } // final hash
|
||||||
|
|
Loading…
Reference in a new issue