From: qydysky Date: Wed, 13 Sep 2023 22:03:15 +0000 (+0800) Subject: add X-Git-Tag: v0.28.0+202309137937674~1 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=a842e5f4a4a5c626efb73965d963f96aef2c4916;p=part%2F.git add --- diff --git a/file/FileWR.go b/file/FileWR.go index 6db827d..157fc11 100644 --- a/file/FileWR.go +++ b/file/FileWR.go @@ -29,7 +29,6 @@ type File struct { file *os.File wr io.Writer rr io.Reader - cu int64 l sync.RWMutex } @@ -366,7 +365,7 @@ func (t *File) SeekIndex(index int64, whence FileWhence) (e error) { } defer t.l.Unlock() - t.cu, e = t.file.Seek(index, int(whence)) + _, e = t.file.Seek(index, int(whence)) return } @@ -455,6 +454,15 @@ func (t *File) Sync() (e error) { return t.file.Sync() } +func (t *File) CurIndex() (ret int64, err error) { + t.getRWCloser() + if t.Config.AutoClose { + defer t.Close() + } + + return t.file.Seek(0, int(AtCurrent)) +} + func (t *File) Create(mode ...fs.FileMode) { t.getRWCloser(mode...) if t.Config.AutoClose { @@ -562,13 +570,12 @@ func (t *File) getRWCloser(mode ...fs.FileMode) { if f, e := os.OpenFile(t.Config.FilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fmode); e != nil { panic(e) } else { - if t.Config.CurIndex > 0 { - t.cu = t.Config.CurIndex - t.cu, e = f.Seek(t.cu, int(AtOrigin)) - if e != nil { - panic(e) - } - } + // if t.Config.CurIndex > 0 { + // _, e = f.Seek(t.Config.CurIndex, int(AtOrigin)) + // if e != nil { + // panic(e) + // } + // } t.file = f } } @@ -584,13 +591,13 @@ func (t *File) getRWCloser(mode ...fs.FileMode) { panic(e) } else { if t.Config.CurIndex != 0 { - t.cu = t.Config.CurIndex + cu := t.Config.CurIndex whenc := AtOrigin if t.Config.CurIndex < 0 { - t.cu = t.cu + 1 + cu += 1 whenc = AtEnd } - t.cu, e = f.Seek(t.cu, int(whenc)) + _, e = f.Seek(cu, int(whenc)) if e != nil { panic(e) }