Skip to content

Commit

Permalink
Optimize passwords/file hash file read with a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Nov 2, 2020
1 parent 43a937b commit b99fad6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/passwords/file/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package file

import (
"bufio"
"bytes"
"context"
"encoding/binary"
Expand Down Expand Up @@ -148,8 +149,9 @@ func (s *Service) IsPasswordCompromised(_ context.Context, sum [20]byte) (count
buf = make([]byte, hashRemainderStep)
passwordHashRemainder := sum[partitionSize:]
hashRemaindersCursor = hashRemaindersStart
hashFileReader := bufio.NewReaderSize(hashFile, int(hashRemainderStep*10))
for hashRemaindersCursor < hashRemaindersEnd {
n, err := hashFile.Read(buf)
n, err := hashFileReader.Read(buf)
if err != nil {
return 0, fmt.Errorf("hashes %v read %v at %v: %w", shard, len(buf), hashRemaindersCursor, err)
}
Expand Down

0 comments on commit b99fad6

Please sign in to comment.