]> 127.0.0.1 Git - part/.git/commitdiff
add
authorqydysky <qydysky@foxmail.com>
Wed, 13 Sep 2023 22:03:15 +0000 (06:03 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 13 Sep 2023 22:03:15 +0000 (06:03 +0800)
file/FileWR.go

index 6db827def5575a9cc182f69b097008913e2f62de..157fc119754fca02050629cf39ad7af3951ac82d 100644 (file)
@@ -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)
                                                }