csv2db/zip.go

28 lines
544 B
Go
Raw Permalink Normal View History

2022-09-18 12:43:16 +05:00
package main
import (
"archive/zip"
"fmt"
2022-10-09 17:23:59 +05:00
"github.com/urfave/cli/v2"
2022-09-18 12:43:16 +05:00
)
2022-10-09 17:23:59 +05:00
func processZipFile(c *cli.Context, filePath string) error {
2022-09-18 12:43:16 +05:00
r, err := zip.OpenReader(filePath)
if err != nil {
2022-09-21 21:36:40 +05:00
return fmt.Errorf("open ZIP file: %v", err)
2022-09-18 12:43:16 +05:00
}
if len(r.File) != 1 {
return fmt.Errorf("supported only one file in archive, got %d files", len(r.File))
}
zipFileReader, err := r.File[0].Open()
if err != nil {
2022-09-21 21:36:40 +05:00
return fmt.Errorf("open file from ZIP archive: %v", err)
2022-09-18 12:43:16 +05:00
}
defer zipFileReader.Close()
2022-10-09 17:23:59 +05:00
return processReader(c, zipFileReader)
2022-09-18 12:43:16 +05:00
}