From a0e38478d304636d045ed3cd15ea227b71bdda1e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 10 May 2011 15:51:10 -0700 Subject: [PATCH] blobserver/remote: ReceiveBlob, which is now easy after previous commits. --- lib/go/camli/blobserver/remote/remote.go | 16 +++++++++++++--- lib/go/camli/client/upload.go | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/go/camli/blobserver/remote/remote.go b/lib/go/camli/blobserver/remote/remote.go index 83868a165..0638444bb 100644 --- a/lib/go/camli/blobserver/remote/remote.go +++ b/lib/go/camli/blobserver/remote/remote.go @@ -64,7 +64,17 @@ func (sto *remoteStorage) Stat(dest chan<- *blobref.SizedBlobRef, blobs []*blobr } func (sto *remoteStorage) ReceiveBlob(blob *blobref.BlobRef, source io.Reader) (*blobref.SizedBlobRef, os.Error) { - return nil, os.NewError("TODO: implement") + h := &client.UploadHandle{ + BlobRef: blob, + Size: -1, // size isn't known; -1 is fine, but TODO: ask source if it knows its size + Contents: source, + } + pr, err := sto.client.Upload(h) + if err != nil { + return nil, err + } + sb := pr.SizedBlobRef() + return &sb, nil // TODO: make this not return a pointer } func (sto *remoteStorage) FetchStreaming(b *blobref.BlobRef) (file io.ReadCloser, size int64, err os.Error) { @@ -75,9 +85,9 @@ func (sto *remoteStorage) MaxEnumerate() uint { return 1000 } func (sto *remoteStorage) EnumerateBlobs(dest chan<- *blobref.SizedBlobRef, after string, limit uint, waitSeconds int) os.Error { return sto.client.EnumerateBlobsOpts(dest, client.EnumerateOpts{ - After: after, + After: after, MaxWaitSec: waitSeconds, - Limit: limit, + Limit: limit, }) } diff --git a/lib/go/camli/client/upload.go b/lib/go/camli/client/upload.go index 0550deac5..a96138777 100644 --- a/lib/go/camli/client/upload.go +++ b/lib/go/camli/client/upload.go @@ -45,6 +45,10 @@ type PutResult struct { Skipped bool // already present on blobserver } +func (pr *PutResult) SizedBlobRef() blobref.SizedBlobRef { + return blobref.SizedBlobRef{pr.BlobRef, pr.Size} +} + type statResponse struct { HaveMap map[string]blobref.SizedBlobRef maxUploadSize int64