summaryrefslogtreecommitdiff
path: root/lib.go
diff options
context:
space:
mode:
authorsachin-puranik <41720019+sachin-puranik@users.noreply.github.com>2020-05-23 10:21:46 +0530
committerGitHub <noreply@github.com>2020-05-23 12:51:46 +0800
commit82bb1153d7b7ff1c50725bf34bd3cbc75b228137 (patch)
tree669767860b56d22a3c17af7910d9d562c692f98d /lib.go
parent0dd616b18fef393ea5b632ba25ca365575f5f61b (diff)
Improved error handling and stoped the crash due to fatel error (#593) close #624
Diffstat (limited to 'lib.go')
-rw-r--r--lib.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib.go b/lib.go
index 41b03c7..5b7e6d0 100644
--- a/lib.go
+++ b/lib.go
@@ -24,10 +24,13 @@ import (
// ReadZipReader can be used to read the spreadsheet in memory without touching the
// filesystem.
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
+ var err error
fileList := make(map[string][]byte, len(r.File))
worksheets := 0
for _, v := range r.File {
- fileList[v.Name] = readFile(v)
+ if fileList[v.Name], err = readFile(v); err != nil {
+ return nil, 0, err
+ }
if strings.HasPrefix(v.Name, "xl/worksheets/sheet") {
worksheets++
}
@@ -53,16 +56,17 @@ func (f *File) saveFileList(name string, content []byte) {
}
// Read file content as string in a archive file.
-func readFile(file *zip.File) []byte {
+func readFile(file *zip.File) ([]byte, error) {
rc, err := file.Open()
if err != nil {
- log.Fatal(err)
+ log.Println(err)
+ return nil, err
}
dat := make([]byte, 0, file.FileInfo().Size())
buff := bytes.NewBuffer(dat)
_, _ = io.Copy(buff, rc)
rc.Close()
- return buff.Bytes()
+ return buff.Bytes(), nil
}
// SplitCellName splits cell name to column name and row number.