OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / spf13 / afero / sftpfs / file.go
1 // Copyright © 2015 Jerry Jacobs <jerry.jacobs@xor-gate.org>.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package sftpfs
15
16 import (
17         "github.com/pkg/sftp"
18         "os"
19 )
20
21 type File struct {
22         fd *sftp.File
23 }
24
25 func FileOpen(s *sftp.Client, name string) (*File, error) {
26         fd, err := s.Open(name)
27         if err != nil {
28                 return &File{}, err
29         }
30         return &File{fd: fd}, nil
31 }
32
33 func FileCreate(s *sftp.Client, name string) (*File, error) {
34         fd, err := s.Create(name)
35         if err != nil {
36                 return &File{}, err
37         }
38         return &File{fd: fd}, nil
39 }
40
41 func (f *File) Close() error {
42         return f.fd.Close()
43 }
44
45 func (f *File) Name() string {
46         return f.fd.Name()
47 }
48
49 func (f *File) Stat() (os.FileInfo, error) {
50         return f.fd.Stat()
51 }
52
53 func (f *File) Sync() error {
54         return nil
55 }
56
57 func (f *File) Truncate(size int64) error {
58         return f.fd.Truncate(size)
59 }
60
61 func (f *File) Read(b []byte) (n int, err error) {
62         return f.fd.Read(b)
63 }
64
65 // TODO
66 func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
67         return 0, nil
68 }
69
70 // TODO
71 func (f *File) Readdir(count int) (res []os.FileInfo, err error) {
72         return nil, nil
73 }
74
75 // TODO
76 func (f *File) Readdirnames(n int) (names []string, err error) {
77         return nil, nil
78 }
79
80 func (f *File) Seek(offset int64, whence int) (int64, error) {
81         return f.fd.Seek(offset, whence)
82 }
83
84 func (f *File) Write(b []byte) (n int, err error) {
85         return f.fd.Write(b)
86 }
87
88 // TODO
89 func (f *File) WriteAt(b []byte, off int64) (n int, err error) {
90         return 0, nil
91 }
92
93 func (f *File) WriteString(s string) (ret int, err error) {
94         return f.fd.Write([]byte(s))
95 }