Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a zip from scratch #113

Open
mar1ged opened this issue Dec 14, 2018 · 3 comments
Open

Creating a zip from scratch #113

mar1ged opened this issue Dec 14, 2018 · 3 comments

Comments

@mar1ged
Copy link

mar1ged commented Dec 14, 2018

Is there really no method that allows me to create a new zip file from scratch and fill it with Files (or Paths in the future)

@toomasr
Copy link
Contributor

toomasr commented Dec 14, 2018

There is something that was added with #112 It seems to have problems on Android I presume. The person hasn't replied back there on platform.

If you need an empty file then why not create it with the standard Java file API? The moment you need to add Zip files you create a zip file.

Then again I see that creating an empty ZIP file is an easy as having a list of predefined bytes there. I just might add it to the library. At least based on https://superuser.com/questions/1205503/empty-zip-file-size-shows-22-bytes-size and https://stackoverflow.com/questions/29234912/how-to-create-minimum-size-empty-zip-file-which-has-22b

@toomasr
Copy link
Contributor

toomasr commented Dec 14, 2018

The master contains the createEmpty implementation that uses the static bytes from https://en.wikipedia.org/wiki/Zip_(file_format)#Limits to create the file. Let me know how this works for you.

@mar1ged
Copy link
Author

mar1ged commented Dec 14, 2018

Thanks a lot for your suggestions. I tried something like this already:

List<ZipEntrySource> files = new ArrayList<ZipEntrySource>();	
... some for Loop that allows me to add each file dynamically
files.add(new FileSource(nameInZip, file);;

ZipEntrySource[] src = new FileSource[files.size()];
ZipEntrySource[] array = files.toArray(src);
ZipUtil.pack(array, new File( "/tmp/file.zip");

It works but I don't like this Approach because it is not very concise due to the List to array conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants