35f98ce162
-Added travis support -updated travis to analyze code beneath the root. -refactored upload.go to fix travis errors. -gocyclo should ignore test files. $GOFILES needed to be adjusted. -fix rows.Close() ignoring error. Created func to handle so defer can be used when needed also. -fixed ignored errors. -fixed unit test that was not passing correctly to anonymous function. -fixed govet error for passing param inside go func. -removed returned error, in favor of logging instead. -added error logging for ignored error. -fixed potential race conditions. -removed unused append -fixed time usage to align with go standards. -removed unused variables -made changes for code review. -code comments for exported functions. -Documented bitmap.go and insert into contact list. -Documented dht, message, bootstrap -Fixed comment typos -Documented message,node, routing_table, testing in DHT package. -Documented server, client, prism, server and shared in peer and reflector packages. -Documented the stores in Store package. -made defer adjustments inline and deleted the separate function. -adjusted method in upload to take the only parameter it requires.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package store
|
|
|
|
import "github.com/lbryio/lbry.go/errors"
|
|
|
|
// MemoryBlobStore is an in memory only blob store with no persistence.
|
|
type MemoryBlobStore struct {
|
|
blobs map[string][]byte
|
|
}
|
|
|
|
// Has returns T/F if the blob is currently stored. It will never error.
|
|
func (m *MemoryBlobStore) Has(hash string) (bool, error) {
|
|
if m.blobs == nil {
|
|
m.blobs = make(map[string][]byte)
|
|
}
|
|
_, ok := m.blobs[hash]
|
|
return ok, nil
|
|
}
|
|
|
|
// Get returns the blob byte slice if present and errors if the blob is not found.
|
|
func (m *MemoryBlobStore) Get(hash string) ([]byte, error) {
|
|
if m.blobs == nil {
|
|
m.blobs = make(map[string][]byte)
|
|
}
|
|
blob, ok := m.blobs[hash]
|
|
if !ok {
|
|
return []byte{}, errors.Err(ErrBlobNotFound)
|
|
}
|
|
return blob, nil
|
|
}
|
|
|
|
// Put stores the blob in memory. It will never error.
|
|
func (m *MemoryBlobStore) Put(hash string, blob []byte) error {
|
|
if m.blobs == nil {
|
|
m.blobs = make(map[string][]byte)
|
|
}
|
|
m.blobs[hash] = blob
|
|
return nil
|
|
}
|
|
|
|
// PutSD stores the sd blob in memory. It will never error.
|
|
func (m *MemoryBlobStore) PutSD(hash string, blob []byte) error {
|
|
//ToDo - need to handle when stream is not present.
|
|
return m.Put(hash, blob)
|
|
}
|