-
Notifications
You must be signed in to change notification settings - Fork 8
/
fs.go
39 lines (31 loc) · 1.05 KB
/
fs.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
package stream
import (
"io"
"os"
)
// File is a backing data-source for a Stream.
type File interface {
Name() string // The name used to Create/Open the File
io.Reader // Reader must continue reading after EOF on subsequent calls after more Writes.
io.ReaderAt // Similarly to Reader
io.Writer // Concurrent reading/writing must be supported.
io.Closer // Close should do any cleanup when done with the File.
}
// FileSystem is used to manage Files
type FileSystem interface {
Create(name string) (File, error) // Create must return a new File for Writing
Open(name string) (File, error) // Open must return an existing File for Reading
Remove(name string) error // Remove deletes an existing File
}
// StdFileSystem is backed by the os package.
var StdFileSystem FileSystem = stdFS{}
type stdFS struct{}
func (fs stdFS) Create(name string) (File, error) {
return os.Create(name)
}
func (fs stdFS) Open(name string) (File, error) {
return os.Open(name)
}
func (fs stdFS) Remove(name string) error {
return os.Remove(name)
}