I am new to golang, I am trying to create a zip that must have a folder inside that is: tosend.zip/archivos/file.png

Juan Camilo Betancourt Giraldo :
newZip, err := os.Create("./temp/tosend.zip")
if err != nil {
    return "", err
}
defer newZip.Close()

zipWriter := zip.NewWriter(newZip)
_, err = zipWriter.Create("archivos/")
if err != nil {
    return "", err
}
defer zipWriter.Close()
iLoveReflection :

You are almost there. A file name can contain directories. Use this code:

zipWriter := zip.NewWriter(newZip)
w, err := zipWriter.Create("archivos/file.png") // <-- use full path here
if err != nil {
    return "", err
}
w.Write(pngData)

Run it on the playground.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error when i am trying to create a zip from 2 files

I am trying to create a dynamic spinner

i am trying to make a new component inside a js variable

when I am trying to create a log_in function?Why I have error Error(3,10): PLS-00215: String length constraints must be in range (1 .. 32767)

I have an input file that I am trying to build a dictionary from

I am new to ruby language , and trying to create a text adventure game , i want to include two strings

I am trying to create a new Cart schema with a request

I have an appointment scheduling application I am trying to create

I am trying to create a C++ map with a vector value inside a boost memory mapped file

I am new to python and i am trying to create a leaderboard

I am new to using mysql - as i was trying to create a table i got the error below

I am trying to position an info box over an image but still have both stay inside the container

I have been trying to create a simple atm program, I am lost

I am trying to install new template for Joomla 3.2 and i have an error for any template

I am trying to write an equation in LaTeX and i have an error

I am trying to create a Clamp method in java

I am trying to create a seven segment scoreboard

If I have struct inside another struct and I am trying to have them inside an array

Why am I getting JSX element must have parent element?

I am trying to create a box in React, and it is not working

I am using Pathlib to open a folder so that i can create a txt file inside of that folder but instead i am getting an error

I am trying to create a new window and execute a function after that new window creation in tkinter

How do i create a .psv file inside each sub-folder that i created? i am using bourne shell script

I am am trying to link the image click to a new product page

I am unable to create a new virtualenv in ubuntu?

I am trying to create a table with sqlite in Kotlin

I am trying to create a subscription but an error occurs

I am trying to create a flight widget

Why am I seeing an 'AttributeError' when using the Python Smartsheet SDK to create a new sheet in a folder?