-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_memory.go
More file actions
35 lines (28 loc) · 828 Bytes
/
source_memory.go
File metadata and controls
35 lines (28 loc) · 828 Bytes
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
package adapt
import (
"io"
"strings"
)
type memoryFSSource struct {
fs map[string]string
}
type memoryFSEntry struct {
name string
}
func (e *memoryFSEntry) IsDir() bool { return false }
func (e *memoryFSEntry) Name() string { return e.name }
func (a *memoryFSSource) ReadDir(_ string) ([]DirEntry, error) {
wrapped := make([]DirEntry, 0)
for name := range a.fs {
wrapped = append(wrapped, &memoryFSEntry{name})
}
return wrapped, nil
}
func (a *memoryFSSource) Open(name string) (io.ReadCloser, error) {
return io.NopCloser(strings.NewReader(a.fs[name])), nil
}
// NewMemoryFSSource provides a SqlStatementsSource for an in-memory filesystem
// represented by a Name->FileContent map
func NewMemoryFSSource(fs map[string]string) SqlStatementsSource {
return FromFilesystemAdapter(&memoryFSSource{fs}, "")
}