From 6925bc8676fb24fad7bebe7b7b921cc3a5bc5ab9 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 20 Apr 2024 17:02:52 +0100 Subject: wip: bad implementation of unzip --- cmd/dbasik-api/return.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cmd/dbasik-api/return.go') diff --git a/cmd/dbasik-api/return.go b/cmd/dbasik-api/return.go index 0973fc9..f172452 100644 --- a/cmd/dbasik-api/return.go +++ b/cmd/dbasik-api/return.go @@ -1,6 +1,7 @@ package main import ( + "archive/zip" "fmt" "github.com/tealeg/xlsx/v3" "path/filepath" @@ -133,6 +134,29 @@ func (fp *DirectoryFilePackage) Prepare() ([]string, error) { return files, nil } +type ZipFilePackage struct { + FilePath string +} + +func (fp *ZipFilePackage) Prepare() ([]string, error) { + // return a slice of the files from inside the zip file pointed to by fh.FilePath + // and an error if any + files, err := zip.OpenReader(fp.FilePath) + if err != nil { + return nil, err + } + defer files.Close() + out := []string{} + for _, file := range files.File { + out = append(out, file.Name) + } + return out, nil +} + func NewDirectoryFilePackage(filePath string) *DirectoryFilePackage { return &DirectoryFilePackage{FilePath: filePath} } + +func NewZipFilePackage(filePath string) *ZipFilePackage { + return &ZipFilePackage{FilePath: filePath} +} -- cgit v1.2.3