Created
July 5, 2011 19:21
-
-
Save botic/1065637 to your computer and use it in GitHub Desktop.
Write into a Zip archive with RingoJS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stuff like this can be added at any time.