mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Correctly handle empty files
Former-commit-id: d166aa352ce4bf32739ddc2f7d1c9967918822fd
This commit is contained in:
@ -4,14 +4,11 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
gzip "github.com/klauspost/pgzip"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||
@ -173,23 +170,21 @@ func ReadGenbank(reader io.Reader, options ...WithOption) obiiter.IBioSequence {
|
||||
|
||||
func ReadGenbankFromFile(filename string, options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
var reader io.Reader
|
||||
var greader io.Reader
|
||||
var err error
|
||||
|
||||
options = append(options, OptionsSource(obiutils.RemoveAllExt((path.Base(filename)))))
|
||||
|
||||
reader, err = os.Open(filename)
|
||||
reader, err = Ropen(filename)
|
||||
|
||||
if err == ErrNoContent {
|
||||
log.Infof("file %s is empty", filename)
|
||||
return ReadEmptyFile(options...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("open file error: %+v", err)
|
||||
return obiiter.NilIBioSequence, err
|
||||
}
|
||||
|
||||
// Test if the flux is compressed by gzip
|
||||
//greader, err = gzip.NewReader(reader)
|
||||
greader, err = gzip.NewReaderN(reader, 1<<24, 2)
|
||||
if err == nil {
|
||||
reader = greader
|
||||
}
|
||||
|
||||
return ReadGenbank(reader, options...), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user