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:
hasheddan 2020-12-08 11:48:42 -06:00
parent 96e0fce629
commit 2d0e327a89
No known key found for this signature in database
GPG Key ID: BD68BC686A14C271
2 changed files with 8 additions and 1 deletions

View File

@ -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) {

View File

@ -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(),
},
}