Jszip: Is there a way to load files into the Zip from remote URL?

Created on 14 Aug 2013  路  14Comments  路  Source: Stuk/jszip

Is there some way to load the files into the Zip from given URLs?? For example something like this:

var zip = new JSZip();
zip.file("Hello.txt", "http://mywebsite.com/files/Hello.txt");
feature

Most helpful comment

Sorry to resurrect a closed issue - but I was wondering if we could get an example of fileURL usage that @sapeish implemented?

All 14 comments

There is no method in JSZip to do that. If you're using a third party library with ajax support (jQuery for example), you can easily GET the _text_ file and put the result into a JSZip instance.

If you try to load a _binary_ file (image, sound, zip) you may be interested in this comment.

@Stuk :
This is a frequent request (loading a remote zip file or adding the content of a remote file). While ajax requests are not in the scope of JSZip, loading binary files in all browsers is hard and we already have everything to do that (used in the unit tests).
Do you think we should separate that code as an extra module ? Not tied to JSZip but to JSZipUtils for example.

Yep, a separate module is appropriate. (sorry for late reply, been on holiday)

Really it should be a separate package (in the NPM/CommonJS sense), but sadly browser packaging isn't there yet (unless something like Mr or Browserify is used)

Actually I already implemented this functionality as a method in JSZIP called fileURL, but before creating a Push Request I gave it to a few users to test it... (no IE tests are being made anyway)

(no IE tests are being made anyway)

After every big change and before every release, I launch the unit tests in all the browsers I have and that includes IE 6 - 10. That's why the homepage says Tested with IE 6 / 7 / 8 / 9 / 10.

@Stuk I'll work on this (I currently work on the documentation and I just can't write "good luck, have fun !" for this part).
I'm ok with a new module (and replace browser-test-utils.js with a dependency to it) and I can create it. Do you prefer a repository on your side (at it makes sense to have stuk/jszip and stuk/jszip-utils) or should I create it on my side ?
And if you find a better name than jszip-utils, don't hesitate :)

Are you planning on adding more functionality than just file downloading? Otherwise something more specific like jszip-download or jszip-remote might be better.

If you're happy having it at Stuk/... then I am too. I've created jszip-utils which we can rename (although we should do that sooner rather than later).

I have no roadmap for this, but adding tools to wrap FileReaders could be a good idea for example. The other popular request is "how do I get the zip file ?" so if we ever find a better answer than FileSaver.js (and encouraging everyone to drop IE <= 9), we could add it too.

I don't mind having it at Stuk/jszip-utils : I prefer the JSZip users to see a consistent ownership and the utils package near the main package rather than an utils package somewhere on github by a unknown (if they don't start digging the commit logs / issue tracker) guy.

I've just released the version 0.0.1 of jszip-utils so I'm closing this issue.

Sorry to resurrect a closed issue - but I was wondering if we could get an example of fileURL usage that @sapeish implemented?

Can we get an example usage?

Here is a sample of how I used the fileURL method I implemented.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lsaes picture Lsaes  路  5Comments

sethdorris picture sethdorris  路  4Comments

ryanakl picture ryanakl  路  4Comments

davejack1 picture davejack1  路  4Comments

sriramkp picture sriramkp  路  6Comments