/
file.go
51 lines (39 loc) · 1.29 KB
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package files
import (
"errors"
"io"
"os"
)
var (
ErrNotDirectory = errors.New("Couln't call NextFile(), this isn't a directory")
ErrNotReader = errors.New("This file is a directory, can't use Reader functions")
)
// File is an interface that provides functionality for handling files/directories
// as values that can be supplied to commands. For directories, child files are
// accessed serially by calling `NextFile()`.
type File interface {
// Files implement ReadCloser, but can only be read from or closed if they are not directories
io.ReadCloser
// FileName returns a full filename path associated with this file
FileName() string
// IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`)
// and false if the File is a normal file (and therefor supports calling `Read` and `Close`)
IsDirectory() bool
// NextFile returns the next child file available (if the File is a directory).
// It will return (nil, io.EOF) if no more files are available.
// If the file is a regular file (not a directory), NextFile will return a non-nil error.
NextFile() (File, error)
}
type StatFile interface {
File
Stat() os.FileInfo
}
type PeekFile interface {
SizeFile
Peek(n int) File
Length() int
}
type SizeFile interface {
File
Size() (int64, error)
}