https://github.com/powerdns/simpleblob
https://github.com/powerdns/simpleblob
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/powerdns/simpleblob
- Owner: PowerDNS
- License: mit
- Created: 2022-04-21T08:11:38.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T18:13:48.000Z (over 1 year ago)
- Last Synced: 2025-03-30T10:41:27.640Z (over 1 year ago)
- Language: Go
- Homepage: https://pkg.go.dev/github.com/PowerDNS/simpleblob
- Size: 147 KB
- Stars: 7
- Watchers: 11
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simpleblob
[](https://pkg.go.dev/github.com/PowerDNS/simpleblob)
[](https://github.com/PowerDNS/simpleblob/actions/workflows/go.yml)
Simpleblob is a Go module that simplifies the storage of arbitrary data by key from Go code. It ships with the following backends:
- `s3`: S3 bucket storage
- `fs`: File storage (one file per blob)
- `memory`: Memory storage (for tests)
## Usage
The interface implemented by the backends is:
```go
type Interface interface {
List(ctx context.Context, prefix string) (BlobList, error)
Load(ctx context.Context, name string) ([]byte, error)
Store(ctx context.Context, name string, data []byte) error
Delete(ctx context.Context, name string) error
}
```
To instantiate a backend, `_`-import all the backends that you want to register, and call:
```go
func GetBackend(ctx context.Context, typeName string, options map[string]any, params ...Param) (Interface, error)
```
An example can be found in `example_test.go`.
Every backend accepts a `map[string]any` with options and performs its own validation on the options. If you use a YAML, TOML and JSON, you could structure it like this:
```go
type Storage struct {
Type string `yaml:"type"`
Options map[string]any `yaml:"options"` // backend specific
}
```
### `io` interfaces
Reading from or writing to a blob directly can be done using the `NewReader` and `NewWriter` functions.
```go
func NewReader(ctx context.Context, storage Interface, blobName string) (io.ReadCloser, error)
func NewWriter(ctx context.Context, storage Interface, blobName string) (io.WriteCloser, error)
```
The returned ReadCloser or WriteCloser is an optimized implementation if the backend being used implements the `StreamReader` or `StreamWriter` interfaces.
If not, a convenience wrapper for the storage is returned.
| Backend | StreamReader | StreamWriter |
| --- | --- | --- |
| S3 | ✔ | ✔ |
| Filesystem | ✔ | ✔ |
| Memory | ✖ | ✖ |
## API Stability
We support the last two stable Go versions, currently 1.22 and 1.23.
From a API consumer point of view, we do not plan any backward incompatible changes before a v1.0.