Instrument the specified zip file.
182865
public void instrumentZipFile(File zf) throws IOException {
        if (!zf.canRead() || !zf.canWrite()) {
            throw new IOException(zf + " can not be replaced");
        }

        File tempFile = File.createTempFile(zf.getName(), null, zf.getParentFile());
        if (tempFile.exists() && !tempFile.delete()) {
            throw new IOException("Unable to delete existing temp file " + tempFile.getName());
        }
        if (!zf.renameTo(tempFile)) {
            throw new IOException("Unable to rename existing jar " + zf);
        }

        ZipFile zipFile = new ZipFile(tempFile);
        FileOutputStream fos = new FileOutputStream(zf);
        ZipOutputStream zos = new ZipOutputStream(fos);
        boolean restoreZipFile = false;
        try {
            byte[] buffer = new byte[8192];
            Enumeration<? extends ZipEntry> e = zipFile.entries();
            while (e.hasMoreElements()) {
                ZipEntry oldEntry = e.nextElement();
                InputStream zis = zipFile.getInputStream(oldEntry);
                byte[] transformedClass = null;

                if (oldEntry.getName().endsWith(".class")) {
                    transformedClass = transform(zis);
                    if (transformedClass == null) {
                        zis = zipFile.getInputStream(oldEntry);
                    }
                }

                ZipEntry newEntry = new ZipEntry(oldEntry.getName());
                newEntry.setTime(transformedClass == null ? oldEntry.getTime() : System.currentTimeMillis());
                newEntry.setComment(oldEntry.getComment());
                newEntry.setExtra(oldEntry.getExtra());
                newEntry.setSize(transformedClass == null ? oldEntry.getSize() : transformedClass.length);

                if (newEntry.getSize() > Integer.MAX_VALUE) {
                    throw new IOException("ZipEntry too large: " + newEntry.getSize());
                }

                int entrySize = (int) newEntry.getSize();
                if (entrySize > buffer.length) {
                    buffer = new byte[entrySize];
                }

                if (transformedClass != null) {
                    System.arraycopy(transformedClass, 0, buffer, 0, entrySize);
                } else {
                    int totalBytesRead = 0;
                    while (totalBytesRead < entrySize) {
                        int bytesRead = zis.read(buffer, totalBytesRead, entrySize - totalBytesRead);
                        if (bytesRead == -1) {
                            throw new IOException("End of file encountered");
                        }
                        totalBytesRead += bytesRead;
                    }
                }

                zos.putNextEntry(newEntry);
                zos.write(buffer, 0, entrySize);
            }
        } catch (IOException ioe) {
            restoreZipFile = true;
            throw ioe;
        } catch (Throwable t) {
            restoreZipFile = true;
            IOException ioe = new IOException("Unexpected exception encountered during instrumentation");
            ioe.initCause(t);
            throw ioe;
        } finally {
            zos.close();
            fos.close();
            zipFile.close();
            if (restoreZipFile) {
                zf.delete();
                tempFile.renameTo(zf);
            } else {
                tempFile.delete();
            }
        }
    }
347689
def from_zip(cls, src='/tmp/app.zip', dest='/app'):
    
    try:
      zf = zipfile.ZipFile(src, 'r')
    except FileNotFoundError:
      raise errors.InvalidPathError(src)
    except zipfile.BadZipFile:
      raise errors.InvalidZipFileError(src)
    [zf.extract(file, dest) for file in zf.namelist()]
    zf.close()
    return cls.from_path(dest)
654428
protected Archive openArchive(File zipFilename) throws IOException {
        try {
            return openArchive(zipFilename, contextUseOptimizedZip);
        } catch (IOException ioe) {
            if (ioe instanceof ZipFileIndex.ZipFormatException) {
                return openArchive(zipFilename, false);
            } else {
                throw ioe;
            }
        }
    }
977915
def extract_zip(zip_path, target_folder):
    
    with zipfile.ZipFile(zip_path) as archive:
        archive.extractall(target_folder)
677026
function coverFile(srcFile) {
      var srcCode = grunt.file.read(srcFile);
      Instrument = require('coverjs').Instrument;

      try {
        return new Instrument(srcCode, {name: srcFile}).instrument();
      } catch (e) {
        grunt.log.error('File ' + srcFile + ' could not be instrumented.');
        grunt.fatal(e, 3);
      }
    }
861845
@Override
    @Trivial
    public ZipFile open() throws IOException {
        String methodName = "open";

        synchronized( zipFileLock ) {
            if ( zipFile == null ) {
                debug(methodName, "Opening");
                if ( zipFileReaper == null ) {
                    zipFile = ZipFileUtils.openZipFile(file); // throws IOException
                } else {
                    zipFile = zipFileReaper.open(path);
                }
            }

            openCount++;
            debug(methodName, "Opened");

            return zipFile;
        }
    }
673821
def compress(info):
    
    if PY3:
        file_obj = BytesIO()
    else:
        file_obj = StringIO()

    with zipfile.ZipFile(
            file_obj,
            mode='w',
            compression=zipfile.ZIP_DEFLATED) as zipper:
        for name, data in info.items():
            if hasattr(data, 'read'):
                # if we were passed a file object, read it
                data = data.read()
            zipper.writestr(name, data)
    file_obj.seek(0)
    compressed = file_obj.read()
    return compressed
598557
public static void zip(File source, File target) throws IOException {
		zip(source, target, null);
	}
530527
private void initializeZip() throws IOException {
		s_logger.info("Using chemical component dictionary: " + m_zipFile.toString());
		final File f = m_zipFile.toFile();
		if (!f.exists()) {
			s_logger.info("Creating missing zip archive: " + m_zipFile.toString());
			FileOutputStream fo = new FileOutputStream(f);
			ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(fo));
			try {
				zip.putNextEntry(new ZipEntry("chemcomp/"));
				zip.closeEntry();
			} finally {
				zip.close();
			}
		}
	}
448368
private static void zip(File file, String srcRootDir, ZipOutputStream out) throws UtilException {
		if (file == null) {
			return;
		}

		final String subPath = FileUtil.subPath(srcRootDir, file); // 获取文件相对于压缩文件夹根目录的子路径
		if (file.isDirectory()) {// 如果是目录，则压缩压缩目录中的文件或子目录
			final File[] files = file.listFiles();
			if (ArrayUtil.isEmpty(files) && StrUtil.isNotEmpty(subPath)) {
				// 加入目录，只有空目录时才加入目录，非空时会在创建文件时自动添加父级目录
				addDir(subPath, out);
			}
			// 压缩目录下的子文件或目录
			for (File childFile : files) {
				zip(childFile, srcRootDir, out);
			}
		} else {// 如果是文件或其它符号，则直接压缩该文件
			addFile(file, subPath, out);
		}
	}
489497
def gunzip(gzip_file, file_gunzip=None):
    """"""
    if file_gunzip is None:
        file_gunzip = os.path.splitext(gzip_file)[0]
        gzip_open_to(gzip_file, file_gunzip)
        return file_gunzip
257594
def current_zipfile():
    """"""
    if zipfile.is_zipfile(sys.argv[0]):
        fd = open(sys.argv[0], "rb")
        return zipfile.ZipFile(fd)
776310
def open(self, name_or_info, mode="r", pwd=None):
        """"""
        # A non-monkey-patched version would contain most of zipfile.py
        ef = super(VerifyingZipFile, self).open(name_or_info, mode, pwd)
        if isinstance(name_or_info, zipfile.ZipInfo):
            name = name_or_info.filename
        else:
            name = name_or_info

        if name in self._expected_hashes and self._expected_hashes[name] is not None:
            expected_hash = self._expected_hashes[name]
            try:
                _update_crc_orig = ef._update_crc
            except AttributeError:
                warnings.warn('Need ZipExtFile._update_crc to implement '
                              'file hash verification (in Python >= 2.7)')
                return ef
            running_hash = self._hash_algorithm()
            if hasattr(ef, '_eof'):  # py33
                def _update_crc(data):
                    _update_crc_orig(data)
                    running_hash.update(data)
                    if ef._eof and running_hash.digest() != expected_hash:
                        raise BadWheelFile("Bad hash for file %r" % ef.name)
            else:
                def _update_crc(data, eof=None):
                    _update_crc_orig(data, eof=eof)
                    running_hash.update(data)
                    if eof and running_hash.digest() != expected_hash:
                        raise BadWheelFile("Bad hash for file %r" % ef.name)
            ef._update_crc = _update_crc
        elif self.strict and name not in self._expected_hashes:
            raise BadWheelFile("No expected hash for file %r" % ef.name)
        return ef
1013543
def CopyFileInZip(from_zip, from_name, to_zip, to_name=None, signer=None):
  """"""
  data = from_zip.read(from_name)
  if to_name is None:
    to_name = from_name
  if signer:
    logging.debug("Signing %s", from_name)
    data = signer.SignBuffer(data)
  to_zip.writestr(to_name, data)
213396
def decompress(compressed_data):
    """"""
    raw_data = []

    index = 0

    while index < len(compressed_data):
        current = compressed_data[index]
        index += 1

        if current == RLE_BYTE:
            directive = compressed_data[index]
            index += 1

            if directive == RLE_BYTE:
                raw_data.append(RLE_BYTE)
            else:
                count = compressed_data[index]
                index += 1

                raw_data.extend([directive] * count)
        elif current == SPECIAL_BYTE:
            directive = compressed_data[index]
            index += 1

            if directive == SPECIAL_BYTE:
                raw_data.append(SPECIAL_BYTE)
            elif directive == DEFAULT_WAVE_BYTE:
                count = compressed_data[index]
                index += 1

                raw_data.extend(DEFAULT_WAVE * count)
            elif directive == DEFAULT_INSTR_BYTE:
                count = compressed_data[index]
                index += 1

                raw_data.extend(DEFAULT_INSTRUMENT_FILEPACK * count)
            elif directive == EOF_BYTE:
                assert False, ("Unexpected EOF command encountered while "
                               "decompressing")
            else:
                assert False, "Countered unexpected sequence 0x%02x 0x%02x" % (
                    current, directive)
        else:
            raw_data.append(current)

    return raw_data
182912
public static void zip(String destination, String source)
            throws FileNotFoundException, IOException {
        zip(new File(destination), new File(source));
    }
961840
public static void mapZipFile(final byte[] zipFile, final Map<String, byte[]> output, final String keyPrefix,
            final String keyUnPrefix) {
        try {
            final String fixedKeyPrefix = keyPrefix == null ? "" : keyPrefix;
            final String fixedKeyUnPrefix = keyUnPrefix == null ? "" : keyUnPrefix;
            final ZipInputStream zf = new ZipInputStream(new ByteArrayInputStream(zipFile));

            ZipEntry ze = null;
            while ((ze = zf.getNextEntry()) != null) {
                final String name = ze.getName();
                final long size = ze.getSize();

                // see if we are working with a file or a directory
                if (size != 0) {
                    byte[] fileContents = new byte[0];
                    final byte[] fileBuffer = new byte[BUFFER_SIZE];

                    int bytesRead = 0;
                    while ((bytesRead = zf.read(fileBuffer, 0, BUFFER_SIZE)) != -1) fileContents = ArrayUtils.addAll(fileContents,
                            bytesRead == BUFFER_SIZE ? fileBuffer : ArrayUtils.subarray(fileBuffer, 0, bytesRead));

                    output.put(fixedKeyPrefix + name.replace(fixedKeyUnPrefix, ""), fileContents);
                }
            }

        } catch (final IOException ex) {
           LOG.error("Unable to read file contents", ex);
        }
    }