Skip to content

Commit

Permalink
More efficient way to fill up images array (#49)
Browse files Browse the repository at this point in the history
* More efficient way to fill up images array

* removed lenImages

Signed-off-by: Enrico Candino <enrico.candino@gmail.com>

Signed-off-by: Enrico Candino <enrico.candino@gmail.com>
Co-authored-by: Enrico Candino <enrico.candino@gmail.com>
  • Loading branch information
larsha and enrichman authored Nov 16, 2022
1 parent e1956f1 commit 9db2ed0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/encrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,24 @@ func (e *Encrypter) getImages(count int) ([]string, error) {
images = append(images, filepath.Join(e.ImagesDir, file.Name()))
}

if len(images) >= count {
break
// if we have sufficient amount of images, we're done, early return
if len(images) == count {
return images, nil
}
}

// TODO we can improve this
lenImages := len(images)
if lenImages == 0 {
if len(images) == 0 {
return nil, errors.Errorf("no image files in %s dir: run 'stego images' to get some random pics", e.ImagesDir)
}

for lenImages < count {
images = append(images, images...)
lenImages = len(images)
// if we don't have sufficient amount of images, fill up with images we have
i := 0
for len(images) < count {
images = append(images, images[i])
i++
}

return images[:count], nil
return images, nil
}

func (e *Encrypter) saveKeysIntoImages(parts []sss.Part, images []string) error {
Expand Down

0 comments on commit 9db2ed0

Please sign in to comment.