aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/dbasik-api/return.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-04-20 17:02:52 +0100
committerMatthew Lemon <y@yulqen.org>2024-04-20 17:02:52 +0100
commit6925bc8676fb24fad7bebe7b7b921cc3a5bc5ab9 (patch)
tree0792731826e013f2cc7feeb9e806b8747053ff30 /cmd/dbasik-api/return.go
parented8a51dd320c5fb003f12003c7a66cfa353f6f81 (diff)
wip: bad implementation of unzip
Diffstat (limited to 'cmd/dbasik-api/return.go')
-rw-r--r--cmd/dbasik-api/return.go24
1 files changed, 24 insertions, 0 deletions
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}
+}