From dec885751e51962b7fdb2c5698bc2574c4387939 Mon Sep 17 00:00:00 2001 From: Phoebe Lartisant Date: Tue, 23 Jul 2024 15:56:23 +0200 Subject: [PATCH] review --- int/zipper/zipper.go | 22 ---------------------- pkg/website/chunk.go | 22 ++++++++++++++++++++++ utils/chunker.go | 18 ------------------ 3 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 int/zipper/zipper.go create mode 100644 pkg/website/chunk.go delete mode 100644 utils/chunker.go diff --git a/int/zipper/zipper.go b/int/zipper/zipper.go deleted file mode 100644 index 1c35b8c..0000000 --- a/int/zipper/zipper.go +++ /dev/null @@ -1,22 +0,0 @@ -package zipper - -import ( - "archive/zip" - "fmt" - "io" -) - -func GetZipFileContent(z *zip.File) ([]byte, error) { - file, err := z.Open() - if err != nil { - return nil, fmt.Errorf("opening zip content: %w", err) - } - defer file.Close() - - content, err := io.ReadAll(file) - if err != nil { - return nil, fmt.Errorf("reading zip content: %w", err) - } - - return content, nil -} diff --git a/pkg/website/chunk.go b/pkg/website/chunk.go new file mode 100644 index 0000000..e4d14e0 --- /dev/null +++ b/pkg/website/chunk.go @@ -0,0 +1,22 @@ +package chunk + +import "fmt" + + +func DivideChunk(data []byte, chunkSize int) ([][]byte, error) { + chunkNumber := len(data)/chunkSize + 1 + + if len(data) < 1 { + return nil, fmt.Errorf("data is empty") + } + + var chunks [][]byte + + for i := 1; i < chunkNumber; i++ { + chunks = append(chunks, data[(i-1)*chunkSize:(i)*chunkSize]) + } + + chunks = append(chunks, data[(chunkNumber-1)*chunkSize:]) + + return chunks, nil +} diff --git a/utils/chunker.go b/utils/chunker.go deleted file mode 100644 index 1cf52cd..0000000 --- a/utils/chunker.go +++ /dev/null @@ -1,18 +0,0 @@ -package chunker - -// Max ChunkSize is half a mb (512kb) -const ChunkSize = 512 - -func DivideChunk(data []byte) [][]byte { - chunkNumber := len(data)/ChunkSize + 1 - - var chunks [][]byte - - for i := 1; i < chunkNumber; i++ { - chunks = append(chunks, data[(i-1)*ChunkSize:(i)*ChunkSize]) - } - - chunks = append(chunks, data[(chunkNumber-1)*ChunkSize:]) - - return chunks -}