mirror of
https://github.com/gogrlx/bitcask.git
synced 2026-04-17 10:35:16 -07:00
Unexport some internal implemtnation details
This commit is contained in:
36
internal/utils.go
Normal file
36
internal/utils.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetDatafiles(path string) ([]string, error) {
|
||||
fns, err := filepath.Glob(fmt.Sprintf("%s/*.data", path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Strings(fns)
|
||||
return fns, nil
|
||||
}
|
||||
|
||||
func ParseIds(fns []string) ([]int, error) {
|
||||
var ids []int
|
||||
for _, fn := range fns {
|
||||
fn = filepath.Base(fn)
|
||||
ext := filepath.Ext(fn)
|
||||
if ext != ".data" {
|
||||
continue
|
||||
}
|
||||
id, err := strconv.ParseInt(strings.TrimSuffix(fn, ext), 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
sort.Ints(ids)
|
||||
return ids, nil
|
||||
}
|
||||
Reference in New Issue
Block a user