Global.helma.Zip.add (f, level, pathPrefix)
adds a single file or a whole directory (recursive!) to the .zip archive

  • Parameter either:
    - (Object) a File object - (Object) an instance of java.io.File - (String) the path to the file that should be added
  • Parameter Int:
    Level to use for compression (default: 9 = best compression)
  • Parameter String:
    name of the directory in the archive into which the file should be added (optional)
  • Returns
    Boolean true
Sourcecode in /home/hannes/helma/modules/helma/Zip.js:
201:   this.add = function (f, level, pathPrefix) {
202:           var f = evalFile(f);
203:   
204:           // evaluate arguments
205:           if (arguments.length == 2) {
206:               if (typeof arguments[1] == "string") {
207:                   pathPrefix = arguments[1];
208:                   level = 9;
209:               } else {
210:                  level = parseInt(arguments[1], 10);
211:                  pathPrefix = null;
212:              }
213:          } else if (level == null || isNaN(level)) {
214:              level = 9;
215:          }
216:          // only levels between 0 and 9 are allowed
217:          level = Math.max(0, Math.min(9, level));
218:  
219:          if (f.isDirectory()) {
220:              // add a whole directory to the zip file (recursive!)
221:              var files = (new helma.File(f.getAbsolutePath())).listRecursive();
222:              for (var i in files) {
223:                  var fAdd = new java.io.File(files[i]);
224:                  if (!fAdd.isDirectory()) {
225:                      var p = fAdd.getPath().substring(f.getAbsolutePath().length, fAdd.getParent().length);
226:                      if (pathPrefix)
227:                          p = pathPrefix + p;
228:                      addFile(zOutStream, fAdd, level, p);
229:                  }
230:              }
231:          } else
232:              addFile(zOutStream, f, level, pathPrefix);
233:          return true;
234:      }