mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
webdav: stream read
This commit is contained in:
parent
65d2ea9fb0
commit
e93e986727
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -89,6 +90,7 @@ type WebDavFile struct {
|
||||||
off int64
|
off int64
|
||||||
entry *filer_pb.Entry
|
entry *filer_pb.Entry
|
||||||
entryViewCache []filer2.VisibleInterval
|
entryViewCache []filer2.VisibleInterval
|
||||||
|
reader io.ReadSeeker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
|
func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
|
||||||
|
@ -494,23 +496,25 @@ func (f *WebDavFile) Read(p []byte) (readSize int, err error) {
|
||||||
}
|
}
|
||||||
if f.entryViewCache == nil {
|
if f.entryViewCache == nil {
|
||||||
f.entryViewCache = filer2.NonOverlappingVisibleIntervals(f.entry.Chunks)
|
f.entryViewCache = filer2.NonOverlappingVisibleIntervals(f.entry.Chunks)
|
||||||
|
f.reader = nil
|
||||||
|
}
|
||||||
|
if f.reader == nil {
|
||||||
|
chunkViews := filer2.ViewFromVisibleIntervals(f.entryViewCache, 0, math.MaxInt32)
|
||||||
|
f.reader = filer2.NewChunkStreamReaderFromClient(f.fs, chunkViews)
|
||||||
}
|
}
|
||||||
chunkViews := filer2.ViewFromVisibleIntervals(f.entryViewCache, f.off, len(p))
|
|
||||||
|
|
||||||
totalRead, err := filer2.ReadIntoBuffer(f.fs, filer2.FullPath(f.name), p, chunkViews, f.off)
|
f.reader.Seek(f.off, io.SeekStart)
|
||||||
|
readSize, err = f.reader.Read(p)
|
||||||
|
|
||||||
|
glog.V(0).Infof("WebDavFileSystem.Read %v: [%d,%d)", f.name, f.off, f.off+int64(readSize))
|
||||||
|
f.off += int64(readSize)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
glog.Errorf("file read %s: %v", f.name, err)
|
||||||
}
|
|
||||||
readSize = int(totalRead)
|
|
||||||
|
|
||||||
glog.V(3).Infof("WebDavFileSystem.Read %v: [%d,%d)", f.name, f.off, f.off+totalRead)
|
|
||||||
|
|
||||||
f.off += totalRead
|
|
||||||
if readSize == 0 {
|
|
||||||
return 0, io.EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WebDavFile) Readdir(count int) (ret []os.FileInfo, err error) {
|
func (f *WebDavFile) Readdir(count int) (ret []os.FileInfo, err error) {
|
||||||
|
|
Loading…
Reference in a new issue