mirror of https://github.com/pkg/sftp.git
Consistent puncutation, names and constants
* European sentence punctuation, consistent with package docs * Match os.SEEK_* constants instead of numeric constants from io.Seeker * Consistent (shorter) receiver name for quickcheck value
This commit is contained in:
parent
68aec0278e
commit
b5d9767c0a
14
client.go
14
client.go
|
@ -634,21 +634,15 @@ func (f *File) Write(b []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seek implements io.Seeker by setting the client offset for the next Read or
|
// Seek implements io.Seeker by setting the client offset for the next Read or
|
||||||
// Write. It returns the next offset read. Seeking before of after the end of
|
// Write. It returns the next offset read. Seeking before or after the end of
|
||||||
// the file is undefined. Seeking relative to the end calls Stat.
|
// the file is undefined. Seeking relative to the end calls Stat.
|
||||||
func (f *File) Seek(offset int64, whence int) (int64, error) {
|
func (f *File) Seek(offset int64, whence int) (int64, error) {
|
||||||
const (
|
|
||||||
SET = 0
|
|
||||||
CUR = 1
|
|
||||||
END = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
switch whence {
|
switch whence {
|
||||||
case SET:
|
case os.SEEK_SET:
|
||||||
f.offset = uint64(offset)
|
f.offset = uint64(offset)
|
||||||
case CUR:
|
case os.SEEK_CUR:
|
||||||
f.offset = uint64(int64(f.offset) + offset)
|
f.offset = uint64(int64(f.offset) + offset)
|
||||||
case END:
|
case os.SEEK_END:
|
||||||
fi, err := f.Stat()
|
fi, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return int64(f.offset), err
|
return int64(f.offset), err
|
||||||
|
|
|
@ -149,31 +149,31 @@ func (s seek) Generate(r *rand.Rand, _ int) reflect.Value {
|
||||||
return reflect.ValueOf(s)
|
return reflect.ValueOf(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg seek) set(t *testing.T, r io.ReadSeeker) {
|
func (s seek) set(t *testing.T, r io.ReadSeeker) {
|
||||||
if _, err := r.Seek(cfg.offset, 0); err != nil {
|
if _, err := r.Seek(s.offset, os.SEEK_SET); err != nil {
|
||||||
t.Fatalf("error while seeking with %+v: %v", cfg, err)
|
t.Fatalf("error while seeking with %+v: %v", s, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg seek) current(t *testing.T, r io.ReadSeeker) {
|
func (s seek) current(t *testing.T, r io.ReadSeeker) {
|
||||||
const mid = seekBytes / 2
|
const mid = seekBytes / 2
|
||||||
|
|
||||||
skip := cfg.offset / 2
|
skip := s.offset / 2
|
||||||
if cfg.offset > mid {
|
if s.offset > mid {
|
||||||
skip = -skip
|
skip = -skip
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := r.Seek(mid, 0); err != nil {
|
if _, err := r.Seek(mid, os.SEEK_SET); err != nil {
|
||||||
t.Fatalf("error seeking to midpoint with %+v: %v", cfg, err)
|
t.Fatalf("error seeking to midpoint with %+v: %v", s, err)
|
||||||
}
|
}
|
||||||
if _, err := r.Seek(skip, 1); err != nil {
|
if _, err := r.Seek(skip, os.SEEK_CUR); err != nil {
|
||||||
t.Fatalf("error seeking from %d with %+v: %v", mid, cfg, err)
|
t.Fatalf("error seeking from %d with %+v: %v", mid, s, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg seek) end(t *testing.T, r io.ReadSeeker) {
|
func (s seek) end(t *testing.T, r io.ReadSeeker) {
|
||||||
if _, err := r.Seek(-cfg.offset, 2); err != nil {
|
if _, err := r.Seek(-s.offset, os.SEEK_END); err != nil {
|
||||||
t.Fatalf("error seeking from end with %+v: %v", cfg, err)
|
t.Fatalf("error seeking from end with %+v: %v", s, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue