@@ -45,44 +45,37 @@ func New(probabilistic bool, limit uint32, fpRatio float64) DejaVu {
45
45
// PROCESS TEXT (for dejavu bin) //
46
46
///////////////////////////////////
47
47
48
- func getReaders (paths []string ) ([]io.Reader , error ) {
49
- readers := make ([]io.Reader , len (paths ))
50
- for i , path := range paths {
48
+ // ProcessPaths is equivalent to Process, only that file paths are given.
49
+ // If - in inputs to use stdin and empty out to use stdout.
50
+ func ProcessPaths (d DejaVu , filter bool , out string , inputs ... string ) error {
51
+
52
+ // get output writer
53
+ var writer * os.File
54
+ if out == "" {
55
+ writer = os .Stdout
56
+ } else {
57
+ writer , err := os .Create (out )
58
+ if err != nil {
59
+ return err
60
+ }
61
+ defer writer .Close ()
62
+ }
63
+
64
+ // get input readers
65
+ readers := make ([]io.Reader , len (inputs ))
66
+ for i , path := range inputs {
51
67
if path == "-" { // read from stdin
52
68
readers [i ] = os .Stdin
53
69
} else { // read from file path
54
70
file , err := os .Open (path )
55
71
if err != nil {
56
- return nil , err
72
+ return err
57
73
}
74
+ defer file .Close ()
58
75
readers [i ] = file
59
76
}
60
77
}
61
- return readers , nil
62
- }
63
78
64
- func getWriter (path string ) (io.Writer , error ) {
65
- if path == "" {
66
- return os .Stdout , nil
67
- }
68
- file , err := os .Create (path )
69
- if err != nil {
70
- return nil , err
71
- }
72
- return file , nil
73
- }
74
-
75
- // ProcessPaths is equivalent to Process, only that file paths are given.
76
- // If - in inputs to use stdin and empty out to use stdout.
77
- func ProcessPaths (d DejaVu , filter bool , out string , inputs ... string ) error {
78
- writer , err := getWriter (out )
79
- if err != nil {
80
- return err
81
- }
82
- readers , err := getReaders (inputs )
83
- if err != nil {
84
- return err
85
- }
86
79
Process (d , filter , writer , readers ... )
87
80
return nil
88
81
}
0 commit comments