Add SkipEmpty FilterFn
The FsReadCloser claimed to implictly skip empty files, but this was only true when the final file to be read was empty. This updates to add a SkipEmpty option that will filter out empty files before even attempting to read file contents. Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
parent
96e0fce629
commit
2d0e327a89
|
|
@ -65,6 +65,13 @@ func SkipDirs() FilterFn {
|
|||
}
|
||||
}
|
||||
|
||||
// SkipEmpty skips empty files.
|
||||
func SkipEmpty() FilterFn {
|
||||
return func(path string, info os.FileInfo) (bool, error) {
|
||||
return info.Size() == 0, nil
|
||||
}
|
||||
}
|
||||
|
||||
// SkipNotYAML skips files that do not have YAML extension.
|
||||
func SkipNotYAML() FilterFn {
|
||||
return func(path string, info os.FileInfo) (bool, error) {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func TestParser(t *testing.T) {
|
|||
"FsBackendSkip": {
|
||||
reason: "should skip empty files and files without yaml extension",
|
||||
parser: New(metaScheme, objScheme),
|
||||
backend: NewFsBackend(emptyFs, FsDir("."), FsFilters(SkipDirs(), SkipNotYAML())),
|
||||
backend: NewFsBackend(emptyFs, FsDir("."), FsFilters(SkipDirs(), SkipEmpty(), SkipNotYAML())),
|
||||
pkg: NewPackage(),
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue