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

Using relative paths #73

Open
mantielero opened this issue Dec 9, 2023 · 2 comments
Open

Using relative paths #73

mantielero opened this issue Dec 9, 2023 · 2 comments

Comments

@mantielero
Copy link

I am trying to store files so that they keep the desire structure within the zipfile.

I see that there is addDir with signature: proc addDir(archive: ZipArchive, base, relative: string). I think it would be a good idea to expose it.

Something similar for addFile would be appreciated. nim-lang/zip has it.

@heysokam
Copy link

The aforementioned solution would only solve the problem for storing entire folders.
The point of addFile is also being able to manually add individual files into an archive.
Otherwise, the currently exposed addDir would suffice, or even the standard createZipArchive would be enough, which is already a thin wrapper for addDir

I also run into this problem, and I'm going to have to resort to using nim-lang/zip, even though I would much prefer to use this lib :(
Hopefully Guzba can get back to this issue sometime in the future. Would be awesome.

@heysokam
Copy link

Actually, I just tried this approach again, and it did work this time 🤷‍♂️

proc zip *(list :seq[Path]; trg :Path; rel :Path= Path".") :void=
  ## @descr Zips the {@arg list} of files into the {@arg trg} file
  var entries: Table[string, string]
  withDir rel:
    for file in list:
      entries[file.relativePath(rel).string] = file.readFile
  trg.writeFile(createZipArchive(entries))

Adding it here for future reference if somebody lands into this issue ✍️

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