erigon-pulse/cl/freezer/store.go
a 21625652f3
[caplin] record mode (#7651)
interface for recording things
2023-06-04 03:13:58 +02:00

54 lines
1.1 KiB
Go

package freezer
import (
"bytes"
"io"
)
type BlobStore struct {
f Freezer
}
func NewBlobStore(f Freezer) *BlobStore {
return &BlobStore{f: f}
}
func (b *BlobStore) Get(namespace, object, id string) ([]byte, error) {
o, _, err := b.f.Get(namespace, object, id)
if err != nil {
return nil, err
}
defer o.Close()
return io.ReadAll(o)
}
func (b *BlobStore) Put(dat []byte, namespace, object, id string) error {
return b.f.Put(bytes.NewBuffer(dat), nil, namespace, object, id)
}
type SidecarBlobStore struct {
f Freezer
}
func NewSidecarBlobStore(f Freezer) *SidecarBlobStore {
return &SidecarBlobStore{f: f}
}
func (b *SidecarBlobStore) Get(namespace, object, id string) (blob []byte, sidecar []byte, err error) {
a, bb, err := b.f.Get(namespace, object, id)
if err != nil {
return nil, nil, err
}
defer a.Close()
sidecar = bb
blob, err = io.ReadAll(a)
if err != nil {
return
}
return
}
func (b *SidecarBlobStore) Put(dat []byte, sidecar []byte, namespace, object, id string) error {
return b.f.Put(bytes.NewBuffer(dat), sidecar, namespace, object, id)
}