Repository: moov-io/ach
Pull request #932 (2021-05-13 17:14:13)

reader: add ReadFiles method for consuming a slice of filepaths

codecov-commenter: # [Codecov](https://codecov.io/gh/moov-io/ach/pull/932?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=moov-io) Report
> Merging [#932](https://codecov.io/gh/moov-io/ach/pull/932?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=moov-io) (c304f39) into [master](https://codecov.io/gh/moov-io/ach/commit/47b96ffbd000e0c5f68b131d56495a18d03c6d7c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=moov-io) (47b96ff) will **decrease** coverage by `0.02%`.
> The diff coverage is `71.42%`.

> :exclamation: Current head c304f39 differs from pull request most recent head 7f1d116. Consider uploading reports for the commit 7f1d116 to get more accurate results

```diff
@@            Coverage Diff             @@
##           master     #932      +/-   ##
==========================================
- Coverage   91.78%   91.75%   -0.03%     
==========================================
  Files          66       66              
  Lines        5219     5226       +7     
==========================================
+ Hits         4790     4795       +5     
- Misses        260      261       +1     
- Partials      169      170       +1     
```


Patch:
diff --git a/reader.go b/reader.go
index 7202993f..b4a0b6fb 100644
--- a/reader.go
+++ b/reader.go
@@ -100,8 +100,8 @@ func (r *Reader) SetValidation(opts *ValidateOpts) {
 	r.File.SetValidation(opts)
 }
 
-// ReadFile attempts to open an os.File at path and read the entire file
-// before closing it and returning the parse result.
+// ReadFile attempts to open a file at path and read the contents before closing
+// and returning the parsed ACH File.
 func ReadFile(path string) (*File, error) {
 	fd, err := os.Open(path)
 	if err != nil {
@@ -113,6 +113,22 @@ func ReadFile(path string) (*File, error) {
 	return &file, err
 }
 
+// ReadFiles attempts to open files at the given paths and read the contents
+// of each before closing and returning the parsed ACH Files.
+func ReadFiles(paths []string) ([]*File, error) {
+	var out []*File
+	for i := range paths {
+		file, err := ReadFile(paths[i])
+		if err != nil {
+			return nil, err
+		}
+		if file != nil {
+			out = append(out, file)
+		}
+	}
+	return out, nil
+}
+
 // NewReader returns a new ACH Reader that reads from r.
 func NewReader(r io.Reader) *Reader {
 	return &Reader{


Test patch:
diff --git a/reader_test.go b/reader_test.go
index 3517372e..9f677170 100644
--- a/reader_test.go
+++ b/reader_test.go
@@ -51,6 +51,20 @@ func TestReadFile(t *testing.T) {
 	}
 }
 
+func TestReadFiles(t *testing.T) {
+	paths := []string{
+		filepath.Join("test", "testdata", "return-WEB.ach"),
+		filepath.Join("test", "testdata", "web-debit.ach"),
+	}
+	files, err := ReadFiles(paths)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if n := len(files); n != 2 {
+		t.Fatalf("read %d files", n)
+	}
+}
+
 func TestReadPartial(t *testing.T) {
 	file, err := ReadFile(filepath.Join("test", "testdata", "bh-ed-ad-bh-ed-ad-ed-ad.ach"))
 	if err != nil {