From a3a1a28d7089d8b8701f8cb4cb30ab13476341f0 Mon Sep 17 00:00:00 2001 From: "Raphael C. Almeida" Date: Sat, 20 Jun 2020 16:46:58 -0300 Subject: [PATCH] Zip in memory initial commit --- .gitignore | 284 +++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + go.mod | 6 + pkg/zip_to_memory.go | 31 +++++ test/pgp_test.go | 10 ++ 5 files changed, 332 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 go.mod create mode 100644 pkg/zip_to_memory.go create mode 100644 test/pgp_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3227ebf --- /dev/null +++ b/.gitignore @@ -0,0 +1,284 @@ + +# Created by https://www.gitignore.io/api/go,vim,linux,macos,emacs,nanoc,sublimetext,jetbrains+all,visualstudiocode +# Edit at https://www.gitignore.io/?templates=go,vim,linux,macos,emacs,nanoc,sublimetext,jetbrains+all,visualstudiocode + +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Linux ### + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Nanoc ### +# For projects using Nanoc (http://nanoc.ws/) + +# Default location for output (needs to match output_dir's value found in nanoc.yaml) +output/ + +# Temporary file directory +tmp/nanoc/ + +# Crash Log +crash.log + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/go,vim,linux,macos,emacs,nanoc,sublimetext,jetbrains+all,visualstudiocode \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..344a520 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Zip To Memory \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4813feb --- /dev/null +++ b/go.mod @@ -0,0 +1,6 @@ +module black_hole + +go 1.14 + +require ( +) diff --git a/pkg/zip_to_memory.go b/pkg/zip_to_memory.go new file mode 100644 index 0000000..8189e51 --- /dev/null +++ b/pkg/zip_to_memory.go @@ -0,0 +1,31 @@ +package pkg + +import ( + "archive/zip" + "bytes" + "errors" + "io/ioutil" +) + +func ExtractZipInMemory(data []byte) ([]byte, error){ + readerAt := bytes.NewReader(data) + r, err := zip.NewReader(readerAt, int64(len(data))) + if err != nil { + return nil, err + } + + for _, f := range r.File { + rc, err := f.Open() + if err != nil { + return nil, err + } + + extractedData, err := ioutil.ReadAll(rc) + if err != nil { + return nil, err + } + rc.Close() + return extractedData, nil + } + return nil, errors.New("empty zip file") +} \ No newline at end of file diff --git a/test/pgp_test.go b/test/pgp_test.go new file mode 100644 index 0000000..cf3a4d6 --- /dev/null +++ b/test/pgp_test.go @@ -0,0 +1,10 @@ +package test + +import ( + "fmt" + "testing" +) + +func TestPGPEncrypt(t *testing.T) { + fmt.Print("Hello world") +}