Global.extractEntry (zFile, entry, destPath)
private function that extracts the data of a file in a .zip archive. If a destination Path is given it writes the extracted data directly to disk using the name of the ZipEntry Object, otherwise it returns the byte array containing the extracted data

  • Parameter Object:
    jAva.util.zip.ZipFile Object
  • Parameter Object:
    java.util.zip.ZipEntry Object to extract
  • Parameter String:
    destination path to extract ZipEntry Object to
  • Returns
    Object ByteArray containing the data of the ZipEntry
Sourcecode in /home/hannes/helma/modules/helma/Zip.js:
46:   var extractEntry = function(zFile, entry, destPath) {
47:           var size = entry.getSize();
48:           if (entry.isDirectory() || size <= 0)
49:               return null;
50:   
51:           var zInStream = new java.io.BufferedInputStream(zFile.getInputStream(entry));
52:           var buf = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, size);
53:           zInStream.read(buf, 0, size);
54:           zInStream.close();
55:  
56:          if (!destPath) {
57:              // no filesystem destination given, so return
58:              // the byte array containing the extracted data
59:              return buf;
60:          }
61:          // extract the file to the given path
62:          var dest = new java.io.File(destPath, entry.getName());
63:          if (entry.isDirectory())
64:              dest.mkdirs();
65:          else if (buf) {
66:              if (!dest.getParentFile().exists())
67:                  dest.getParentFile().mkdirs();
68:              try {
69:                  var outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(dest));
70:                  outStream.write(buf, 0, size);
71:              } finally {
72:                  outStream.close();
73:              }
74:          }
75:          return null;
76:      }