Home Download Docs Code Community
     1	/*
     2	Copyright 2014 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	package mongo
    18	
    19	import (
    20		"bytes"
    21		"context"
    22		"fmt"
    23		"io"
    24	
    25		"gopkg.in/mgo.v2/bson"
    26		"perkeep.org/pkg/blob"
    27	)
    28	
    29	func (m *mongoStorage) Fetch(ctx context.Context, ref blob.Ref) (io.ReadCloser, uint32, error) {
    30		var b blobDoc
    31		err := m.c.Find(bson.M{"key": ref.String()}).One(&b)
    32		if err != nil {
    33			return nil, 0, err
    34		}
    35		if len(b.Blob) != int(b.Size) {
    36			return nil, 0, fmt.Errorf("blob data size %d doesn't match meta size %d", len(b.Blob), b.Size)
    37		}
    38		return io.NopCloser(bytes.NewReader(b.Blob)), b.Size, nil
    39	}
Website layout inspired by memcached.
Content by the authors.