File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed
Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change 55 "errors"
66 "fmt"
77 "github.com/OpenListTeam/OpenList/v4/internal/conf"
8+ "github.com/rclone/rclone/lib/mmap"
89 "io"
910 "math"
1011 "os"
@@ -179,26 +180,30 @@ func (f *FileStream) RangeRead(httpRange http_range.Range) (io.Reader, error) {
179180
180181func (f * FileStream ) cache (maxCacheSize int64 ) (model.File , error ) {
181182 limit := int64 (conf .MaxBufferLimit )
182- // TODO: 这里不会改,我写成了buf := make([]byte, 64<<10)的形式
183- //var buf []byte
184- //if conf.MmapThreshold > 0 && limit >= int64(conf.MmapThreshold) {
185- // m, err := mmap.Alloc(int(limit))
186- // if err == nil {
187- // f.Add(utils.CloseFunc(func() error {
188- // return mmap.Free(m)
189- // }))
190- // buf = m
191- // }
192- //}
193183
194184 if f .peekBuff == nil {
195185 f .peekBuff = & buffer.Reader {}
196186 f .oriReader = f .Reader
197187 }
188+ var buf []byte
189+ bufSize := 64 << 10 // 64KB as default
190+ if conf .MmapThreshold > 0 && bufSize >= conf .MmapThreshold {
191+ m , err := mmap .Alloc (bufSize )
192+ if err == nil {
193+ f .Add (utils .CloseFunc (func () error {
194+ return mmap .Free (m )
195+ }))
196+ buf = m
197+ }
198+ }
199+
198200 var readBytes int
199201 // precache first `limit` byte
200202 for int64 (readBytes ) < limit {
201- buf := make ([]byte , 64 << 10 )
203+ if buf == nil {
204+ buf = make ([]byte , bufSize )
205+ }
206+
202207 want := limit - int64 (readBytes )
203208 if want > int64 (len (buf )) {
204209 want = int64 (len (buf ))
You can’t perform that action at this time.
0 commit comments