Skip to content

Commit 5fd5872

Browse files
Merge pull request #1 from AskAlexSharov/no_hash_at_start
method to unmarshal without checksum
2 parents 4da4cf7 + 1dba2e7 commit 5fd5872

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

v2/binaryunmarshaler.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,34 @@ func (f *Filter) UnmarshalFromReader(input io.Reader) (n int64, err error) {
131131
}
132132
return buf.tot, nil
133133
}
134+
135+
// noopHash implements hash.Hash interface but does nothing
136+
type noopHash struct{}
137+
138+
func (h *noopHash) Write(p []byte) (n int, err error) { return len(p), nil }
139+
func (h *noopHash) Sum(b []byte) []byte { return b }
140+
func (h *noopHash) Reset() {}
141+
func (h *noopHash) Size() int { return 0 }
142+
func (h *noopHash) BlockSize() int { return 64 }
143+
144+
func (f *Filter) UnmarshalFromReaderNoVerify(input io.Reader) (n int64, err error) {
145+
buf := &hashingReader{
146+
reader: input,
147+
hasher: &noopHash{},
148+
}
149+
var k uint64
150+
k, f.n, f.m, err = unmarshalBinaryHeader(input)
151+
if err != nil {
152+
return buf.tot, err
153+
}
154+
keys, err := unmarshalBinaryKeys(input, k)
155+
if err != nil {
156+
return buf.tot, err
157+
}
158+
copy(f.keys[:], keys)
159+
f.bits, err = unmarshalBinaryBits(buf, f.m)
160+
if err != nil {
161+
return buf.tot, err
162+
}
163+
return buf.tot, nil
164+
}

0 commit comments

Comments
 (0)