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(
|
s := store.NewCachingBlobStore(
|
||||||
peer.NewStore(addr),
|
peer.NewStore(addr),
|
||||||
store.NewFileBlobStore("/tmp/lbry_downloaded_blobs", 2),
|
store.NewDiskBlobStore("/tmp/lbry_downloaded_blobs", 2),
|
||||||
)
|
)
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/lbryio/lbry.go/extras/errors"
|
"github.com/lbryio/lbry.go/extras/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileBlobStore is a local disk store.
|
// DiskBlobStore stores blobs on a local disk
|
||||||
type FileBlobStore struct {
|
type DiskBlobStore struct {
|
||||||
// the location of blobs on disk
|
// the location of blobs on disk
|
||||||
blobDir string
|
blobDir string
|
||||||
// store files in subdirectories based on the first N chars in the filename. 0 = don't create subdirectories.
|
// 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
|
initialized bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFileBlobStore returns an initialized file disk store pointer.
|
// NewDiskBlobStore returns an initialized file disk store pointer.
|
||||||
func NewFileBlobStore(dir string, prefixLength int) *FileBlobStore {
|
func NewDiskBlobStore(dir string, prefixLength int) *DiskBlobStore {
|
||||||
return &FileBlobStore{blobDir: dir, prefixLength: prefixLength}
|
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 {
|
if f.prefixLength <= 0 || len(hash) < f.prefixLength {
|
||||||
return f.blobDir
|
return f.blobDir
|
||||||
}
|
}
|
||||||
return path.Join(f.blobDir, hash[:f.prefixLength])
|
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)
|
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))
|
return errors.Err(os.MkdirAll(dir, 0755))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FileBlobStore) initOnce() error {
|
func (f *DiskBlobStore) initOnce() error {
|
||||||
if f.initialized {
|
if f.initialized {
|
||||||
return nil
|
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.
|
// 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()
|
err := f.initOnce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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.
|
// 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()
|
err := f.initOnce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -88,7 +88,7 @@ func (f *FileBlobStore) Get(hash string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put stores the blob on disk
|
// 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()
|
err := f.initOnce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -103,12 +103,12 @@ func (f *FileBlobStore) Put(hash string, blob []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutSD stores the sd blob on the disk
|
// 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)
|
return f.Put(hash, blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes the blob from the store
|
// Delete deletes the blob from the store
|
||||||
func (f *FileBlobStore) Delete(hash string) error {
|
func (f *DiskBlobStore) Delete(hash string) error {
|
||||||
err := f.initOnce()
|
err := f.initOnce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue