impl map stream
This commit is contained in:
28
map_stream.go
Executable file
28
map_stream.go
Executable file
@@ -0,0 +1,28 @@
|
||||
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 {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.Set(key, b, ns...)
|
||||
}
|
||||
Reference in New Issue
Block a user