2

I have several files in a GridFS Document Store and what I'd like to do is to pipe this data into a zip file via stdin in NodeJS. So that I will end up with a zip file containing all these files.

Now my question is how can I give the files a valid filename inside of the zip file. I think I need to emulate/fake a file header containing the filename?

Any help is appreciated!

Thanks

sled
  • 14,525
  • 3
  • 42
  • 70

1 Answers1

4

I had problems when writing zip files with Node.js not long ago. I ended up doing something similar to what is described in Zip archives in node.js

I can't help you directly with your problem, but at least I hope I can point out some things:

  • Don't try to use node-archive. Even if the description says it allows to create zip files, the moment I read the source code (since documentation is unexistant) I realized that's just a lie. It only exposes methods for reading.
  • Using zip by spawning a process, like recommended on the provided link, seems to be the best way. Something that would work is copying the files to a local folder with whatever name you desire and then calling the zip command, just to delete the files afterwards.
  • The other option, which seems ok, is to use zipper (https://github.com/rubenv/zipper, although better just use npm). The reason I'm not really wishing to use it is because there's not that much flexibility, it seems to have been done in a day and it hasn't been modified since the first commit, so I'm not sure it will receive maintenance (sure, you could just fork it...).

I swear the day I have an entire free weekend with no work I will write a freaking module that does this as complete as possible. It's silly that there isn't and it shouldn't be that much struggle. blablablarant.

Edit: Not sure if it was there before, but now I've been using the node-compress module (also using gzippo). It works fine.

Community
  • 1
  • 1
Mamsaac
  • 6,173
  • 3
  • 21
  • 30
  • hi, I'd join you writing a nice zip library :) I went for the spawning process streaming the output of stdout ;) but it would be nice if we could stream data to stdin of the zip process without persisting the files to the hard drive. – sled Oct 11 '11 at 07:00
  • Awesome answer. Thank you. – The Dembinski Mar 04 '17 at 19:29