file *os.File
wr io.Writer
rr io.Reader
+ cu int64
sync.RWMutex
}
if index < 0 {
whenc = 2
}
- t.Config.CurIndex, e = t.file.Seek(index, whenc)
+ t.cu, e = t.file.Seek(index, whenc)
return nil
}
if t.file != nil {
if e := t.file.Close(); e != nil {
return e
+ } else {
+ t.file = nil
}
}
return nil
panic(e)
} else {
if t.Config.CurIndex > 0 {
- t.Config.CurIndex, e = f.Seek(t.Config.CurIndex, 0)
+ t.cu = t.Config.CurIndex
+ t.cu, e = f.Seek(t.cu, 0)
if e != nil {
panic(e)
}
panic(e)
} else {
if t.Config.CurIndex != 0 {
+ t.cu = t.Config.CurIndex
whenc := 0
if t.Config.CurIndex < 0 {
+ t.cu = t.cu + 1
whenc = 2
}
- t.Config.CurIndex, e = f.Seek(t.Config.CurIndex, whenc)
+ t.cu, e = f.Seek(t.cu, whenc)
if e != nil {
panic(e)
}
)
func TestWriteReadDelSync(t *testing.T) {
- f := New("test/rwd.txt", -1, true)
- if i, e := f.Write([]byte("sss"), true); i == 0 || e != nil {
+ f := New("test/rwd.txt", -6, true)
+ if i, e := f.Write([]byte("sssa\n"), true); i == 0 || e != nil {
t.Fatal(e)
}
- var buf = make([]byte, 3)
+ var buf = make([]byte, 5)
if i, e := f.Read(buf); i == 0 || e != nil {
t.Fatal(i, e)
} else {
- if !bytes.Equal(buf[:i], []byte("sss")) {
- t.Fatal(string(buf[:i]), e)
+ if !bytes.Equal(buf[:i], []byte("sssa\n")) {
+ t.Fatal(i, string(buf), e)
}
}
if i, e := f.Read(buf); i == 0 || e != nil {
t.Fatal(i, e)
} else {
- for _, v := range buf {
- if v != 's' {
- t.Fatal(v)
- }
+ if !bytes.Equal(buf[:i], []byte("sssa\n")) {
+ t.Fatal(i, string(buf), e)
}
}