get rid of duplicate bytes.Buffer, use bytes.Reader instead, #39

This commit is contained in:
2024-01-27 17:23:09 +01:00
parent e092ce7b8e
commit 5728c1eab3
7 changed files with 19 additions and 14 deletions

View File

@@ -33,7 +33,7 @@ const MaxDistance = 3
type Image struct {
Filename string
Hash *goimagehash.ImageHash
Data *bytes.Buffer
Data *bytes.Reader
URI string
}
@@ -49,7 +49,7 @@ func (img *Image) LogValue() slog.Value {
// holds all images of an ad
type Cache []*goimagehash.ImageHash
func NewImage(buf *bytes.Buffer, filename string, uri string) *Image {
func NewImage(buf *bytes.Reader, filename string, uri string) *Image {
img := &Image{
Filename: filename,
URI: uri,
@@ -131,7 +131,9 @@ func ReadImages(addir string, dont bool) (Cache, error) {
return nil, err
}
img := NewImage(data, filename, "")
reader := bytes.NewReader(data.Bytes())
img := NewImage(reader, filename, "")
if err = img.CalcHash(); err != nil {
return nil, err
}