kineapps / flutter_archive

Flutter plugin for creating and extracting ZIP files.
https://pub.dev/packages/flutter_archive
BSD 3-Clause "New" or "Revised" License
59 stars 44 forks source link

Why does it have a sourceDir argument in ZipFile.createFromFiles? #66

Closed ash-hashtag closed 1 year ago

ash-hashtag commented 1 year ago

Shouldn't List files would be enough? So I selected some files from different places, So they aren't in a single directory, So should I keep the sourceDir to be the root Directory of the entire phone? I think the best would be to copy all the files to some tempDir and pass it? But still what has it anything to do? List files goes in --> A Zip File should come out, I mean yeah write to a zip file, but why take a sourceDir?

kinex commented 1 year ago

SourceDir is needed to get the relative path of the files. The relative paths of the files are saved to the zip.

For example files:

/a/b/c/file1.txt
/a/b/c/d/file2.txt

If sourceDir is /a/b, the relative paths are:

c/file1.txt
c/d/file2.txt

If sourceDir is /a, the relative paths are:

b/c/file1.txt
b/c/d/file2.txt
ash-hashtag commented 1 year ago

isn't copying files just to a directory, just for zipping them is a waste?

kinex commented 1 year ago

Did you already try with sourceDir="/" ?

ash-hashtag commented 1 year ago

Nope, but that should make very long nested files according to the explanation, right?

kinex commented 1 year ago

Yes. It could be useful to allow sourceDir being null, in which case all listed files would be zipped without path information. Duplicate file names would be a problem though (maybe just overwrite or throw error). PRs also welcome :)