Would it be possible to create a client-site only application written in JavaScript (that runs in a browser) which gets multiple image files via ajax, then compresses them as zip (or tar or whatever) and returns it to the user as a file download (without any server-side logic)?
Workflow would be like this:
- Open website mydomain.com in a browser
- Website collects images from
mydomain.com/images/image1.png
andmydomain.com/images/image2.jpg
via ajax. - Both files are now automatically compressed into an archive file (e.g. zip, gzip or tar or whatever)
- User gets the usual download prompt for his browser for this archive file.
So far I think I can get part 1-2 running via jQuery:
var urls = [
'image1.png',
'image2.jpg'
];
var images = [];
var counter = 0;
function createArchive(images){
// How to implement this?
}
function download(archive){
// How to implement this?
}
for (var i = 0; i<urls.length; i++) {
$.ajax('images/' + urls[i]).done(function(data) {
images.push(data);
counter++;
// Offer download of archive when all ajax calls are done
if (counter == urls.length){
var archive = createArchive(images);
download(archive);
}
});
}
But from here I don't know how to create the zip file from the images array. How would I do that?
Important: This has to run in all majors browsers like IE, Firefox, Chrome, Safari