Skip to content

Instantly share code, notes, and snippets.

@botic
Created July 5, 2011 19:21
Show Gist options
  • Save botic/1065637 to your computer and use it in GitHub Desktop.
Save botic/1065637 to your computer and use it in GitHub Desktop.
Write into a Zip archive with RingoJS.
var fs = require("fs");
var writeToZip = function(files, dest, filePrefix) {
var fos = new java.io.FileOutputStream(dest);
var zos = new java.util.zip.ZipOutputStream(fos);
files.forEach(function(file, index) {
var ze = new java.util.zip.ZipEntry((filePrefix || "") + fs.base(file));
var data = fs.read(file, "b");
zos.putNextEntry(ze);
zos.write(data);
zos.closeEntry();
});
zos.close();
fos.close();
};
writeToZip([
"/Users/Philipp/Pictures/tmp-pola/PN_20110703-2133-01.jpg",
"/Users/Philipp/Pictures/tmp-pola/PN_20110703-2140-02.jpg",
"/Users/Philipp/Pictures/tmp-pola/PN_20110703-2143-03.jpg",
"/Users/Philipp/Pictures/tmp-pola/PN_20110703-2145-04.jpg",
"/Users/Philipp/Pictures/tmp-pola/PN_20110703-2150-05.jpg"
], "/Users/Philipp/Pictures/tmp-pola/_exported_" + (new Date()).getTime() + ".zip");
@hns
Copy link

hns commented Jul 5, 2011

Stuff like this can be added at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment