-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upload tests; natstream internal
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package natstream | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/facette/natsort" | ||
) | ||
|
||
var ( | ||
ErrEndStream = errors.New("no more files in natstream") | ||
) | ||
|
||
type NatStream struct { | ||
files []string | ||
idx int | ||
} | ||
|
||
func (ns *NatStream) Init(glob string) error { | ||
files, err := filepath.Glob(glob) | ||
if err != nil { | ||
return err | ||
} | ||
ns.files = files | ||
natsort.Sort(ns.files) | ||
ns.idx = 0 | ||
|
||
return nil | ||
} | ||
|
||
func (ns *NatStream) Next() (string, error) { | ||
if ns.idx == len(ns.files) { | ||
return "", ErrEndStream | ||
} | ||
data, err := os.ReadFile(ns.files[ns.idx]) | ||
if err != nil { | ||
return "", err | ||
} | ||
ns.idx++ | ||
|
||
return string(data), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters