rename FileStore -> DiskStore
This commit is contained in:
parent
a8230db802
commit
0af6d65d40
2 changed files with 15 additions and 15 deletions
|
@ -30,7 +30,7 @@ func getStreamCmd(cmd *cobra.Command, args []string) {
|
|||
|
||||
s := store.NewCachingBlobStore(
|
||||
peer.NewStore(addr),
|
||||
store.NewFileBlobStore("/tmp/lbry_downloaded_blobs", 2),
|
||||
store.NewDiskBlobStore("/tmp/lbry_downloaded_blobs", 2),
|
||||
)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
)
|
||||
|
||||
// FileBlobStore is a local disk store.
|
||||
type FileBlobStore struct {
|
||||
// DiskBlobStore stores blobs on a local disk
|
||||
type DiskBlobStore struct {
|
||||
// the location of blobs on disk
|
||||
blobDir string
|
||||
// store files in subdirectories based on the first N chars in the filename. 0 = don't create subdirectories.
|
||||
|
@ -18,27 +18,27 @@ type FileBlobStore struct {
|
|||
initialized bool
|
||||
}
|
||||
|
||||
// NewFileBlobStore returns an initialized file disk store pointer.
|
||||
func NewFileBlobStore(dir string, prefixLength int) *FileBlobStore {
|
||||
return &FileBlobStore{blobDir: dir, prefixLength: prefixLength}
|
||||
// NewDiskBlobStore returns an initialized file disk store pointer.
|
||||
func NewDiskBlobStore(dir string, prefixLength int) *DiskBlobStore {
|
||||
return &DiskBlobStore{blobDir: dir, prefixLength: prefixLength}
|
||||
}
|
||||
|
||||
func (f *FileBlobStore) dir(hash string) string {
|
||||
func (f *DiskBlobStore) dir(hash string) string {
|
||||
if f.prefixLength <= 0 || len(hash) < f.prefixLength {
|
||||
return f.blobDir
|
||||
}
|
||||
return path.Join(f.blobDir, hash[:f.prefixLength])
|
||||
}
|
||||
|
||||
func (f *FileBlobStore) path(hash string) string {
|
||||
func (f *DiskBlobStore) path(hash string) string {
|
||||
return path.Join(f.dir(hash), hash)
|
||||
}
|
||||
|
||||
func (f *FileBlobStore) ensureDirExists(dir string) error {
|
||||
func (f *DiskBlobStore) ensureDirExists(dir string) error {
|
||||
return errors.Err(os.MkdirAll(dir, 0755))
|
||||
}
|
||||
|
||||
func (f *FileBlobStore) initOnce() error {
|
||||
func (f *DiskBlobStore) initOnce() error {
|
||||
if f.initialized {
|
||||
return nil
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func (f *FileBlobStore) initOnce() error {
|
|||
}
|
||||
|
||||
// Has returns T/F or Error if it the blob stored already. It will error with any IO disk error.
|
||||
func (f *FileBlobStore) Has(hash string) (bool, error) {
|
||||
func (f *DiskBlobStore) Has(hash string) (bool, error) {
|
||||
err := f.initOnce()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -70,7 +70,7 @@ func (f *FileBlobStore) Has(hash string) (bool, error) {
|
|||
}
|
||||
|
||||
// Get returns the byte slice of the blob stored or will error if the blob doesn't exist.
|
||||
func (f *FileBlobStore) Get(hash string) ([]byte, error) {
|
||||
func (f *DiskBlobStore) Get(hash string) ([]byte, error) {
|
||||
err := f.initOnce()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -88,7 +88,7 @@ func (f *FileBlobStore) Get(hash string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// Put stores the blob on disk
|
||||
func (f *FileBlobStore) Put(hash string, blob []byte) error {
|
||||
func (f *DiskBlobStore) Put(hash string, blob []byte) error {
|
||||
err := f.initOnce()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -103,12 +103,12 @@ func (f *FileBlobStore) Put(hash string, blob []byte) error {
|
|||
}
|
||||
|
||||
// PutSD stores the sd blob on the disk
|
||||
func (f *FileBlobStore) PutSD(hash string, blob []byte) error {
|
||||
func (f *DiskBlobStore) PutSD(hash string, blob []byte) error {
|
||||
return f.Put(hash, blob)
|
||||
}
|
||||
|
||||
// Delete deletes the blob from the store
|
||||
func (f *FileBlobStore) Delete(hash string) error {
|
||||
func (f *DiskBlobStore) Delete(hash string) error {
|
||||
err := f.initOnce()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue