예제 #1
0
func (sto *fakeStorage) Fetch(b blob.Ref) (file io.ReadCloser, size uint32, err error) {
	bb, ok := sto.blobs[b.String()]

	if !ok {
		return file, size, errors.New("Blob not found")
	}

	return bb.Open(), bb.Size(), err
}
예제 #2
0
func (s *swiftStorage) refContainer(b blob.Ref) (name string, container string) {
	ref := b.String()
	idx := strings.Index(ref, "/")

	if idx > 0 && len(ref) > idx+1 {
		return ref[idx+1:], ref[:idx]
	}

	return b.String(), s.container(b)
}
예제 #3
0
func (s *swiftStorage) container(b blob.Ref) string {
	if !s.shard {
		return s.containerName
	}

	ref := b.String()
	idx := strings.Index(ref, "/")

	if idx > 0 {
		return ref[:idx]
	}

	return fmt.Sprintf("%s-%s", s.containerName, shards.shard(ref[:]))
}
예제 #4
0
//func NewBlob(ref Ref, size uint32, newReader func() io.ReadCloser) Blob {
func (sto *fakeStorage) ReceiveBlob(b blob.Ref, source io.Reader) (sb blob.SizedRef, err error) {
	buf := &bytes.Buffer{}
	size, err := io.Copy(buf, source)

	if err != nil {
		return sb, err
	}

	newBlob := blob.NewBlob(b, uint32(size), func() io.ReadCloser {
		return ioutil.NopCloser(bytes.NewReader(buf.Bytes()))
	})

	sto.blobs[b.String()] = newBlob
	return newBlob.SizedRef(), err
}
예제 #5
0
func (sto *s3Storage) ReceiveBlob(b blob.Ref, source io.Reader) (sr blob.SizedRef, err error) {
	slurper := newAmazonSlurper(b)
	defer slurper.Cleanup()

	size, err := io.Copy(slurper, source)
	if err != nil {
		return sr, err
	}

	err = sto.s3Client.PutObject(b.String(), sto.bucket, slurper.md5, size, slurper)
	if err != nil {
		return sr, err
	}
	b.SetHash(slurper.md5)
	return blob.SizedRef{Ref: b, Size: uint32(size)}, nil
}
예제 #6
0
func (sto *s3Storage) Fetch(blob blob.Ref) (file io.ReadCloser, size uint32, err error) {
	file, sz, err := sto.s3Client.Get(sto.bucket, blob.String())
	return file, uint32(sz), err
}