-
Notifications
You must be signed in to change notification settings - Fork 1
/
input_file.go
30 lines (25 loc) · 681 Bytes
/
input_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
package modzy
import (
"io"
"github.com/pkg/errors"
)
// FileInputEncodable is a data input that can be provided when using Jobs().SubmitJobFile(...).
//
// Provided implementations of this function are:
// FileInputReader
// FileInputFile
type FileInputEncodable func() (io.Reader, error)
func FileInputReader(data io.Reader) FileInputEncodable {
return func() (io.Reader, error) {
return data, nil
}
}
func FileInputFile(filename string) FileInputEncodable {
return func() (io.Reader, error) {
file, err := AppFs.Open(filename)
if err != nil {
return nil, errors.WithMessagef(err, "Failed to open file: %s", filename)
}
return FileInputReader(file)()
}
}