storj/storage/listkeys.go
Egon Elbre 8bef560ab9 storage: delete unused code and lower visibility of static iterator
Change-Id: I8ec6ec9a710650611d272b03b2927759a8b02f91
2020-02-17 14:53:54 +00:00

35 lines
793 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package storage
import (
"context"
)
// ListKeys returns keys starting from first and upto limit.
// limit is capped to LookupLimit.
func ListKeys(ctx context.Context, store KeyValueStore, first Key, limit int) (_ Keys, err error) {
defer mon.Task()(&ctx)(&err)
if limit <= 0 || limit > store.LookupLimit() {
limit = store.LookupLimit()
}
keys := make(Keys, 0, limit)
err = store.Iterate(ctx, IterateOptions{
First: first,
Recurse: true,
}, func(ctx context.Context, it Iterator) error {
var item ListItem
for ; limit > 0 && it.Next(ctx, &item); limit-- {
if item.Key == nil {
panic("nil key")
}
keys = append(keys, CloneKey(item.Key))
}
return nil
})
return keys, err
}