Skip to content

Instantly share code, notes, and snippets.

@botic
Created July 5, 2011 19:21
Show Gist options
  • Select an option

  • Save botic/1065637 to your computer and use it in GitHub Desktop.

Select an option

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

hns commented Jul 5, 2011

Copy link
Copy Markdown

Would be really cool to have write support in ringo/zip!
http://ringojs.org/api/master/ringo/zip/

@botic

botic commented Jul 5, 2011

Copy link
Copy Markdown
Author

Something for 0.9? I expected that feature already in ringo 0.7 ;-)

@hns

hns commented Jul 5, 2011

Copy link
Copy Markdown

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