Add blobref.SeekerFromStreamingFetcher, moving it from UI code.

This commit is contained in:
Brad Fitzpatrick 2011-06-08 17:48:56 -07:00
parent f31959c24c
commit a4c43c359f
2 changed files with 15 additions and 13 deletions

View File

@ -178,3 +178,17 @@ func (s *MemoryStore) FetchStreaming(b *BlobRef) (file io.ReadCloser, size int64
}
return ioutil.NopCloser(strings.NewReader(str)), int64(len(str)), nil
}
func SeekerFromStreamingFetcher(f StreamingFetcher) (SeekFetcher, os.Error) {
seeker, ok := f.(SeekFetcher)
if ok {
return seeker, nil
}
tester, ok := f.(SeekTester)
if ok {
if tester.IsFetcherASeeker() {
return &FetcherToSeekerWrapper{f}, nil
}
}
return nil, fmt.Errorf("bloref: TODO: SeekerFromStreamingFetcher: %T %v doesn't support seeking. TODO: wrap in a write-to-disk-and-read wrapper and/or cache", f, f)
}

View File

@ -250,19 +250,7 @@ func (ui *UIHandler) serveUploadHelper(rw http.ResponseWriter, req *http.Request
}
func (ui *UIHandler) storageSeekFetcher() (blobref.SeekFetcher, os.Error) {
fetchSeeker, ok := ui.Storage.(blobref.SeekFetcher)
if ok {
return fetchSeeker, nil
}
tester, ok := ui.Storage.(blobref.SeekTester)
if ok {
if tester.IsFetcherASeeker() {
log.Printf("ui.Storage is a seeker; returning wrapper")
return &blobref.FetcherToSeekerWrapper{ui.Storage}, nil
}
}
return nil, fmt.Errorf("TODO: ui.Storage of %T %v doesn't support seeking. TODO: wrap in a cache",
ui.Storage, ui.Storage)
return blobref.SeekerFromStreamingFetcher(ui.Storage)
}
func (ui *UIHandler) serveDownload(rw http.ResponseWriter, req *http.Request) {