mirror of https://github.com/perkeep/perkeep.git
Add blobref.SeekerFromStreamingFetcher, moving it from UI code.
This commit is contained in:
parent
f31959c24c
commit
a4c43c359f
|
@ -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)
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue