mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-21 03:29:55 -06:00
34 lines
620 B
Go
34 lines
620 B
Go
package storage
|
|
|
|
import (
|
|
"errors"
|
|
"hash"
|
|
"io"
|
|
)
|
|
|
|
type hasher struct {
|
|
dest io.WriteCloser
|
|
len int
|
|
sum hash.Hash
|
|
closeCallback func(int, hash.Hash, error) error
|
|
}
|
|
|
|
func (c *hasher) Read(p []byte) (n int, err error) {
|
|
return 0, errors.New("read not supported")
|
|
}
|
|
|
|
func (c *hasher) Write(p []byte) (n int, err error) {
|
|
n, err = c.dest.Write(p)
|
|
c.sum.Write(p)
|
|
c.len += n
|
|
return
|
|
}
|
|
|
|
func (c *hasher) Seek(offset int64, whence int) (int64, error) {
|
|
return 0, errors.New("seek not supported")
|
|
}
|
|
|
|
func (c *hasher) Close() error {
|
|
return c.closeCallback(c.len, c.sum, c.dest.Close())
|
|
}
|