/*
Promisify ZipFile `close` method
421212
function promisifyClose(ZipFile, Promise) {
	const close = ZipFile.prototype.close;

	ZipFile.prototype.close = function() {
		return new Promise((resolve, reject) => {
			if (getError(this)) return rejectWithStoredError(this, reject);
			if (!this.isOpen) return resolve();
			if (getState(this)) return reject(new Error('Previous operation has not completed yet'));

			setState(this, {action: 'close', resolve, reject});
			close.call(this);
		});
	};
}
41982
def pop(self):
        """"""
        if not self.fp:
            raise RuntimeError(
                  "Attempt to pop from ZIP archive that was already closed")
        last = self.infolist().pop()
        del self.NameToInfo[last.filename]
        self.fp.seek(last.header_offset, os.SEEK_SET)
        self.fp.truncate()
        self._didModify = True
1352738
public static void unzip(Path zip, Path target) throws IOException {
        try (final ZipFile zipFile = new ZipFile(zip.toFile())){
            unzip(zipFile, target);
        }
    }
659955
function promisify(repl) {
  var _eval = repl.eval;
  repl.eval = function(cmd, context, filename, callback) {
    _eval.call(repl, cmd, context, filename, function(err, res) {
      if (isPromiseLike(res)) {
        res.then(function(ret) {
          callback(null, ret);
        }, function(err) {
          callback(err);
        });
      } else {
        callback(err, res);
      }
    });
  };
  return repl;
}
1341392
function ReadZipFile(zip, file) {
    return new Promise((resolve, reject) => {
        var data = "";
        zip.openReadStream(file, function(err, readStream) {
            if (err) {
                return reject(err);
            }

            readStream.on("data", function(chunk) {
                data += chunk;
            }).on("end", function() {
                // parse JSON data
                try {
                    data = JSON.parse(data);
                    return resolve(data);
                } catch (e) {
                    return reject(`JSON parse error extracting ${file.fileName}: ${e}`);
                }
            });
        });
    });
}
925558
public static void zip(File source, File target, String compressFileName) throws IOException {
		$.notNull(source);
		zip(new File[] { source }, target, compressFileName);
	}
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);
                }
            }
        }
    }
375572
function promisifyMethod(yauzl, Promise, fnName) {
	const fromBuffer = fnName == 'fromBuffer';

	cloner.patch(yauzl, fnName, original => {
		return function(path, totalSize, options) {
			return new Promise((resolve, reject) => {
				options = Object.assign({}, options, {lazyEntries: true, autoClose: false});

				original(path, totalSize, options, (err, zipFile) => {
					if (err) return reject(err);
					opened(zipFile, resolve, fromBuffer, yauzl);
				});
			});
		};
	});
}
1106438
function promisify(err, value, callback) {
  if (err) { throw err; }
  if (isPromiseLike(value)) {
    value.then(function(v) {
      callback(null, v);
    }, function(err) {
      callback(err);
    });
  } else {
    callback(null, value);
  }
}
966356
public static void zipInto(File target, File... files) {
        ZipOutputStream zos = null;
        try {
            zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
            byte[] buffer = new byte[128];
            for (File f : files) {
                ZipEntry entry = new ZipEntry(f.getName());
                InputStream is = new BufferedInputStream(new FileInputStream(f));
                zos.putNextEntry(entry);
                int read = 0;
                while ((read = is.read(buffer)) != -1) {
                    zos.write(buffer, 0, read);
                }
                zos.closeEntry();
                IO.close(is);
            }
        } catch (IOException e) {
            throw E.ioException(e);
        } finally {
            IO.close(zos);
        }
    }
668146
function promisify(f, args) {
  return new Promise((resolve, reject) => f.apply(this, args.concat((err, x) => err ? reject(err) : resolve(x))));
}
420712
function fileClosed(file) {
        if (!file) {
            return;
        }
        var language = LanguageManager.getLanguageForPath(file._path),
            size = -1;

        function _sendData(fileSize) {
            var subType = "";

            if(fileSize/1024 <= 1) {

                if(fileSize < 0) {
                    subType = "";
                }
                if(fileSize <= 10) {
                    subType = "Size_0_10KB";
                } else if (fileSize <= 50) {
                    subType = "Size_10_50KB";
                } else if (fileSize <= 100) {
                    subType = "Size_50_100KB";
                } else if (fileSize <= 500) {
                    subType = "Size_100_500KB";
                } else {
                    subType = "Size_500KB_1MB";
                }

            } else {
                fileSize = fileSize/1024;
                if(fileSize <= 2) {
                    subType = "Size_1_2MB";
                } else if(fileSize <= 5) {
                    subType = "Size_2_5MB";
                } else {
                    subType = "Size_Above_5MB";
                }
            }

            sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_CLOSE + language._name + subType,
                                commonStrings.USAGE,
                                commonStrings.FILE_CLOSE,
                                language._name.toLowerCase(),
                                subType
                             );
        }

        file.stat(function(err, fileStat) {
            if(!err) {
                size = fileStat.size.valueOf()/1024;
            }
            _sendData(size);
        });
    }
78331
public void close() throws IOException {
        if (closeRequested)
            return;
        guard.close();
        closeRequested = true;

        synchronized (this) {
            // Close streams, release their inflaters
            synchronized (streams) {
                if (false == streams.isEmpty()) {
                    Map<InputStream, Inflater> copy = new HashMap<>(streams);
                    streams.clear();
                    for (Map.Entry<InputStream, Inflater> e : copy.entrySet()) {
                        e.getKey().close();
                        Inflater inf = e.getValue();
                        if (inf != null) {
                            inf.end();
                        }
                    }
                }
            }

            // Release cached inflaters
            Inflater inf;
            synchronized (inflaterCache) {
                while (null != (inf = inflaterCache.poll())) {
                    inf.end();
                }
            }

            if (jzfile != 0) {
                // Close the zip file
                long zf = this.jzfile;
                jzfile = 0;

                close(zf);
            }

            // Android-changed, explicit delete for OPEN_DELETE ZipFile.
            if (fileToRemoveOnClose != null) {
                fileToRemoveOnClose.delete();
            }
        }
    }
220390
public static void compress(File dir, File zipFile) throws IOException {

    FileOutputStream fos = new FileOutputStream(zipFile);
    ZipOutputStream zos = new ZipOutputStream(fos);

    recursiveAddZip(dir, zos, dir);

    zos.finish();
    zos.close();

  }
576725
@Override
    protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
            long lastModified, File fromArchive, int mode) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IoUtil.copy(is, baos, buf);
        struct.data = baos.toByteArray();
        struct.name = vPath;
        struct.time = lastModified;
        if (proc.process(struct) != JarProcessor.Result.DISCARD) {
            if (mode == 0)
                mode = ZipFileSet.DEFAULT_FILE_MODE;
            if (!filesOnly) {
                addParentDirs(struct.name, zOut);
            }
            super.zipFile(new ByteArrayInputStream(struct.data),
                    zOut, struct.name, struct.time, fromArchive, mode);
        }
    }
888308
public function finalize($output)
    {
        $zipFileUrl = sys_get_temp_dir() . '/' . uniqid();

        $this->fillZipWithFileContents($zipFileUrl);
        if (!$this->zip->close()) {
            throw new \RuntimeException('Failed to close zip file!');
        }

        $this->copyToOutputAndCleanup($output, $zipFileUrl);
    }
714221
func (z *ZipFile) Close() error {
	err := z.Writer.Close()
	// If the out writer supports io.Closer, Close it.
	if c, ok := z.out.(io.Closer); ok {
		c.Close()
	}
	return err
}