1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
11
"github.com/juju/errors"
13
"github.com/juju/juju/state/storage"
16
type MapStorage struct {
21
var _ storage.Storage = (*MapStorage)(nil)
23
func (s *MapStorage) Get(path string) (r io.ReadCloser, length int64, err error) {
24
data, ok := s.Map[path]
26
return nil, -1, errors.NotFoundf("%s", path)
28
return ioutil.NopCloser(bytes.NewReader(data)), int64(len(data)), nil
31
func (s *MapStorage) Put(path string, r io.Reader, length int64) error {
33
s.Map = make(map[string][]byte)
35
buf := make([]byte, int(length))
36
_, err := io.ReadFull(r, buf)
44
func (s *MapStorage) Remove(path string) error {
45
if _, ok := s.Map[path]; !ok {
46
return errors.NotFoundf("%s", path)