Skip to content

Commit

Permalink
Added possibility to give url as input alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jan 26, 2018
1 parent d386fae commit 0bd0603
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"errors"
"fmt"
goio "io"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -74,7 +75,7 @@ Please note that in --auto-detect mode, phylip format is considered as not stric
}

func readalign(file string) align.AlignChannel {
var fi *os.File
var fi goio.Closer
var r *bufio.Reader
var err error
var format int
Expand Down
39 changes: 28 additions & 11 deletions io/utils/readfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"compress/gzip"
"io"
"net/http"
"os"
"strings"
)
Expand All @@ -23,23 +24,34 @@ func OpenFile(inputfile string) (*os.File, error) {
}

/* Returns the opened file and a buffered reader (gzip or not) for the file */
func GetReader(inputfile string) (*os.File, *bufio.Reader, error) {
func GetReader(inputfile string) (io.Closer, *bufio.Reader, error) {
var reader *bufio.Reader
if f, err := OpenFile(inputfile); err != nil {
return nil, nil, err

var err error
var f io.ReadCloser

if isHttpFile(inputfile) {
var res *http.Response
if res, err = http.Get(inputfile); err != nil {
return nil, nil, err
}
f = res.Body
} else {
if f, err = OpenFile(inputfile); err != nil {
return nil, nil, err
}
}

if GzipExtension(f.Name()) {
if gr, err := gzip.NewReader(f); err != nil {
return nil, nil, err
} else {
reader = bufio.NewReader(gr)
}
if GzipExtension(inputfile) {
if gr, err := gzip.NewReader(f); err != nil {
return nil, nil, err
} else {
reader = bufio.NewReader(f)
reader = bufio.NewReader(gr)
}
return f, reader, nil
} else {
reader = bufio.NewReader(f)
}
return f, reader, nil
}

/* Returns a buffered reader (gzip or not) for the given reader */
Expand All @@ -60,3 +72,8 @@ func GzipExtension(name string) (gzipped bool) {
gzipped = strings.HasSuffix(name, ".gz")
return
}

func isHttpFile(file string) bool {
return strings.HasPrefix(file, "http://") ||
strings.HasPrefix(file, "https://")
}

0 comments on commit 0bd0603

Please sign in to comment.