-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnull.go
More file actions
51 lines (41 loc) · 1.23 KB
/
null.go
File metadata and controls
51 lines (41 loc) · 1.23 KB
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 reader
import (
"bytes"
"context"
"github.com/whosonfirst/go-ioutil"
"io"
)
// NullReader is a struct that implements the `Reader` interface for reading documents from nowhere.
type NullReader struct {
Reader
}
func init() {
ctx := context.Background()
err := RegisterReader(ctx, "null", NewNullReader)
if err != nil {
panic(err)
}
}
// NewNullReader returns a new `FileReader` instance for reading documents from nowhere,
// configured by 'uri' in the form of:
//
// null://
//
// Technically 'uri' can also be an empty string.
func NewNullReader(ctx context.Context, uri string) (Reader, error) {
r := &NullReader{}
return r, nil
}
// Read will open and return an empty `io.ReadSeekCloser` for any value of 'path'.
func (r *NullReader) Read(ctx context.Context, path string) (io.ReadSeekCloser, error) {
br := bytes.NewReader([]byte(""))
return ioutil.NewReadSeekCloser(br)
}
// Exists returns a boolean value indicating whether 'path' already exists (meaning it will always return false).
func (r *NullReader) Exists(ctx context.Context, path string) (bool, error) {
return false, nil
}
// ReaderURI returns the value of 'path'.
func (r *NullReader) ReaderURI(ctx context.Context, path string) string {
return path
}