32 lines
516 B
Go
Executable File
32 lines
516 B
Go
Executable File
package storage
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
)
|
|
|
|
type MapStream struct {
|
|
*Map
|
|
}
|
|
|
|
func NewMapStream() *MapStream {
|
|
return &MapStream{NewMap()}
|
|
}
|
|
|
|
func (m *MapStream) GetStream(key string, ns ...string) (io.Reader, error) {
|
|
b, err := m.Get(key, ns...)
|
|
return bytes.NewReader(b), err
|
|
}
|
|
|
|
func (m *MapStream) SetStream(key string, r io.Reader, ns ...string) error {
|
|
if r == nil {
|
|
return m.Set(key, nil, ns...)
|
|
}
|
|
b, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return m.Set(key, b, ns...)
|
|
}
|