2021-12-20 06:43:14 +00:00
|
|
|
package filer
|
|
|
|
|
|
|
|
type ReaderPattern struct {
|
|
|
|
isStreaming bool
|
|
|
|
lastReadOffset int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// For streaming read: only cache the first chunk
|
|
|
|
// For random read: only fetch the requested range, instead of the whole chunk
|
|
|
|
|
|
|
|
func NewReaderPattern() *ReaderPattern {
|
|
|
|
return &ReaderPattern{
|
|
|
|
isStreaming: true,
|
2021-12-23 00:05:38 +00:00
|
|
|
lastReadOffset: -1,
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
|
|
|
if rp.lastReadOffset > offset {
|
|
|
|
rp.isStreaming = false
|
|
|
|
}
|
2021-12-23 00:05:38 +00:00
|
|
|
if rp.lastReadOffset == -1 {
|
|
|
|
if offset != 0 {
|
|
|
|
rp.isStreaming = false
|
|
|
|
}
|
|
|
|
}
|
2021-12-20 06:43:14 +00:00
|
|
|
rp.lastReadOffset = offset
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *ReaderPattern) IsStreamingMode() bool {
|
|
|
|
return rp.isStreaming
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *ReaderPattern) IsRandomMode() bool {
|
|
|
|
return !rp.isStreaming
|
|
|
|
}
|