unpack...

@param zip the zip
@param patchDir the patch dir
@throws IOException
351801
private static void unzip(final ZipFile zip, final File patchDir) throws IOException {
        final Enumeration<? extends ZipEntry> entries = zip.entries();
        while(entries.hasMoreElements()) {
            final ZipEntry entry = entries.nextElement();
            final String name = entry.getName();
            final File current = new File(patchDir, name);
            if(entry.isDirectory()) {
                continue;
            } else {
                if(! current.getParentFile().exists()) {
                    current.getParentFile().mkdirs();
                }
                try (final InputStream eis = zip.getInputStream(entry)){
                    Files.copy(eis, current.toPath());
                    //copy(eis, current);
                }
            }
        }
    }
957092
def _unpack(self):
        
        if self._ext == 'zip':
            with ZipFile(self._local, 'r') as archive:
                archive.extractall(self._root)
        else:
            cmd = 'gunzip | tar xC ' + self._root
            proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE)
            proc.stdin.write(self._local.read())
        self._local.close()
761126
def unpack(self, buff, offset=0):
        
        unpack_length = UBInt16()
        unpack_length.unpack(buff, offset)
        super().unpack(buff[:offset+unpack_length], offset)
661646
function unzipWorker(unzipTask, workerCb) {
  var zipfile = unzipTask.zipfile;
  var entry = unzipTask.entry;
  var workingDir = unzipTask.workingDir;
  if (/\/$/.test(entry.fileName)) {
    // directory file names end with '/'
    makeExportDirectory({
      entry: entry,
      zipfile: zipfile,
      workingDir: workingDir
    }, workerCb);
  } else {
    // file entry
    streamFileEntry({
      zipfile: zipfile,
      entry: entry,
      workingDir: workingDir
    }, workerCb);
  }
}
186718
public static void repack(File zip, int compressionLevel) {
    try {
      File tmpZip = FileUtils.getTempFileFor(zip);

      repack(zip, tmpZip, compressionLevel);

      // Delete original zip
      if (!zip.delete()) {
        throw new IOException("Unable to delete the file: " + zip);
      }

      // Rename the archive
      FileUtils.moveFile(tmpZip, zip);
    }
    catch (IOException e) {
      throw ZipExceptionUtil.rethrow(e);
    }
  }
249883
public void processFile(File zipFile, File destDir) throws IOException {
        if (!destDir.exists()) {
            throw new IOException("Destionation directory '" + destDir + "' does not exists, or can't be read!");
        }
        ZipFile f = null;
        try {
            f = new ZipFile(zipFile);
            Map<String, ZipEntry> fEntries = getEntries(f);
            String[] names = fEntries.keySet().toArray(new String[] {});
            if (sortNames) {
                Arrays.sort(names);
            }
            // copy all files
            for (int i = 0; i < names.length; i++) {
                String name = names[i];
                ZipEntry e = fEntries.get(name);
                copyFileEntry(destDir, f, e);
            }
        } catch (IOException ioe) {
            String msg = ioe.getMessage();
            if (msg.indexOf(zipFile.toString()) < 0) {
                msg += " - " + zipFile.toString();
            }
            throw new IOException(msg);
        } finally {
            if (f != null) {
                try {
                    f.close();
                } catch (IOException ioe) {
                }
            }
        }
    }
114522
public static void unzip(String jarFile, Path destination) throws IOException {
        Map<String, String> zipProperties = new HashMap<>();
        /* We want to read an existing ZIP File, so we set this to false */
        zipProperties.put("create", "false");
        zipProperties.put("encoding", "UTF-8");
        URI zipFile = URI.create("jar:" + jarFile);

        try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, zipProperties)) {
            Path rootPath = zipfs.getPath("/");
            Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                    Path targetPath = destination.resolve(rootPath.relativize(dir).toString());
                    if (!Files.exists(targetPath)) {
                        Files.createDirectory(targetPath);
                    }
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.copy(file, destination.resolve(rootPath.relativize(file).toString()), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
                    return FileVisitResult.CONTINUE;
                }
            });
        }
    }
582443
def unzip_file_to_dir(path_to_zip, output_directory):
    
    z = ZipFile(path_to_zip, 'r')
    z.extractall(output_directory)
    z.close()
185237
public void unzip(String zipFile, String location) throws IOException {
        final int BUFFER_SIZE = 10240;
        int size;
        byte[] buffer = new byte[BUFFER_SIZE];

        try {
            if (!location.endsWith("/")) {
                location += "/";
            }
            File f = new File(location);
            if (!f.isDirectory()) {
                f.mkdirs();
            }
            ZipInputStream zin = new ZipInputStream(
                    new BufferedInputStream(new FileInputStream(zipFile), BUFFER_SIZE));
            try {
                ZipEntry ze = null;
                while ((ze = zin.getNextEntry()) != null) {
                    String path = location + ze.getName();
                    File unzipFile = new File(path);

                    if (ze.isDirectory()) {
                        if (!unzipFile.isDirectory()) {
                            unzipFile.mkdirs();
                        }
                    } else {
                        // check for and create parent directories if they don't exist
                        File parentDir = unzipFile.getParentFile();
                        if (null != parentDir) {
                            if (!parentDir.isDirectory()) {
                                parentDir.mkdirs();
                            }
                        }

                        // unzip the file
                        FileOutputStream out = new FileOutputStream(unzipFile, false);
                        BufferedOutputStream fout = new BufferedOutputStream(out, BUFFER_SIZE);
                        try {
                            while ((size = zin.read(buffer, 0, BUFFER_SIZE)) != -1) {
                                fout.write(buffer, 0, size);
                            }

                            zin.closeEntry();
                        } finally {
                            fout.flush();
                            fout.close();
                        }
                    }
                }
            } finally {
                zin.close();
            }
        } catch (Exception e) {
            Log.e(TAG, "Unzip exception", e);
        }
    }
728271
public int zip(OutputStream out, DirScanner scanner) throws IOException, InterruptedException {
        return archive(ArchiverFactory.ZIP, out, scanner);
    }
95321
private boolean unZip(String innerDir, String archiveFile) {
        boolean success = true;
        ZipFile zipFile;
        try {
            zipFile = new ZipFile(archiveFile);
            // Get the list of file headers from the zip file before unpacking
            List fileHeaderList = zipFile.getFileHeaders();

            List<PathMatcher> matchers = Arrays.stream(filesExcludes).map(fileExclude ->
                    FileSystems.getDefault().getPathMatcher(GLOB_PREFIX + fileExclude)).collect(Collectors.toList());
            // Loop through the file headers and extract only files that are not matched by fileExcludes patterns
            for (int i = 0; i < fileHeaderList.size(); i++) {
                FileHeader fileHeader = (FileHeader) fileHeaderList.get(i);
                String fileName = fileHeader.getFileName();
                if (filesExcludes.length > 0) {
                    Predicate<PathMatcher> matchesExcludes = pathMatcher -> pathMatcher.matches(Paths.get(innerDir, fileName));
                    if (matchers.stream().noneMatch(matchesExcludes)) {
                        zipFile.extractFile(fileHeader, innerDir);
                    }
                } else {
                    zipFile.extractFile(fileHeader, innerDir);
                }
            }
        } catch (Exception e) {
            success = false;
            logger.warn("Error extracting file {}: {}", archiveFile, e.getMessage());
            logger.debug("Error extracting file {}: {}", archiveFile, e.getStackTrace());
        } finally {
            // remove reference to zip file
            zipFile = null;
        }
        return success;
    }
944196
@Override
    public void deleteUnpackedWAR(StandardContext standardContext)
    {
        File unpackDir = new File(standardHost.getAppBase(), standardContext.getPath().substring(1));
        if (unpackDir.exists())
        {
            ExpandWar.deleteDir(unpackDir);
        }
    }
1106726
public static boolean unzipFileIntoDirectory(final File zipFile, final String directory) {
        final Map<ZipEntry, byte[]> zipEntries = new HashMap<ZipEntry, byte[]>();
        ZipInputStream zis;
        try {
            zis = new ZipInputStream(new FileInputStream(zipFile));
        } catch (FileNotFoundException ex) {
            LOG.error("Unable to find specified file", ex);
            return false;
        }
        ZipEntry entry = null;
        byte[] buffer = new byte[1024];
        try {
            int read;
            while ((entry = zis.getNextEntry()) != null) {
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
                while ((read = zis.read(buffer)) > 0) {
                    bos.write(buffer, 0, read);
                }
                zipEntries.put(entry, bos.toByteArray());
            }
        } catch (IOException ex) {
            LOG.error("Unable to write ZIP file to directory", ex);
            return false;
        }
        return unzipFileIntoDirectory(zipEntries, directory);
    }
1278787
private void zipDirectory(String zipFile, String dirToZip) {
    File directory = new File(dirToZip);
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(zipFile))) {
      addDirectoryToZip(directory, directory, stream);
    } catch (Exception e) {
      throw new PlatformManagerException("Failed to zip module", e);
    }
  }
450581
private static void processZipStream(File dir, InputStream inputStream) throws IOException
   {
      ZipInputStream zip = new ZipInputStream(inputStream);
      while (true)
      {
         ZipEntry entry = zip.getNextEntry();
         if (entry == null)
         {
            break;
         }

         File file = new File(dir, entry.getName());
         if (entry.isDirectory())
         {
            FileHelper.mkdirsQuietly(file);
            continue;
         }

         File parent = file.getParentFile();
         if (parent != null)
         {
            FileHelper.mkdirsQuietly(parent);
         }

         FileOutputStream fos = new FileOutputStream(file);
         byte[] bytes = new byte[1024];
         int length;
         while ((length = zip.read(bytes)) >= 0)
         {
            fos.write(bytes, 0, length);
         }
         fos.close();
      }
   }
162100
public static Map<String, byte[]> unzipFile(final byte[] zipBytes, boolean stripZIPName) throws IOException {
        final Map<ZipEntry, byte[]> zipEntries = new HashMap<ZipEntry, byte[]>();
        final ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes));
        ZipEntry entry = null;
        byte[] buffer = new byte[1024];
        int read;
        while ((entry = zis.getNextEntry()) != null) {
            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            while ((read = zis.read(buffer)) > 0) {
                bos.write(buffer, 0, read);
            }
            zipEntries.put(entry, bos.toByteArray());
        }

        final HashMap<String, byte[]> files = new HashMap<String, byte[]>();
        for (final Entry<ZipEntry, byte[]> mapEntry : zipEntries.entrySet()) {
            final ZipEntry zipEntry = mapEntry.getKey();
            // Ignore directories, as we only want files
            if (!zipEntry.isDirectory()) {
                if (stripZIPName) {
                    files.put(stripZipFileName(zipEntry.getName()), mapEntry.getValue());
                } else {
                    files.put(zipEntry.getName(), mapEntry.getValue());
                }
            }
        }

        return files;
    }
242850
function unzip(src, dst) {
  return load(src).then(zip => {
    let promisedDirs = new Map;
    let promises = [];

    zip.z_.forEach((relPath, file) => {
      let p;
      if (file.dir) {
        p = createDir(relPath);
      } else {
        let dirname = path.dirname(relPath);
        if (dirname === '.') {
          p = writeFile(relPath, file);
        } else {
          p = createDir(dirname).then(() => writeFile(relPath, file));
        }
      }
      promises.push(p);
    });

    return Promise.all(promises).then(() => dst);

    function createDir(dir) {
      let p = promisedDirs.get(dir);
      if (!p) {
        p = io.mkdirp(path.join(dst, dir));
        promisedDirs.set(dir, p);
      }
      return p;
    }

    function writeFile(relPath, file) {
      return file.async('nodebuffer')
          .then(buffer => io.write(path.join(dst, relPath), buffer));
    }
  });
}