make a zip file from the rawr tile formatted data
335646
def make_rawr_zip_payload(rawr_tile, date_time=None):
    """"""
    if date_time is None:
        date_time = gmtime()[0:6]

    buf = StringIO()
    with zipfile.ZipFile(buf, mode='w') as z:
        for fmt_data in rawr_tile.all_formatted_data:
            zip_info = zipfile.ZipInfo(fmt_data.name, date_time)
            z.writestr(zip_info, fmt_data.data, zipfile.ZIP_DEFLATED)
    return buf.getvalue()
942599
def extract_zip(archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    try:
        with zipfile.ZipFile(archive) as zfile:
            zfile.extractall(outdir)
    except Exception as err:
        msg = "error extracting %s: %s" % (archive, err)
        raise util.PatoolError(msg)
    return None
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)
677509
def MakeZip(self, input_dir, output_file):
    
    logging.info("Generating zip template file at %s", output_file)
    basename, _ = os.path.splitext(output_file)
    # TODO(user):pytype: incorrect make_archive() definition in typeshed.
    # pytype: disable=wrong-arg-types
    shutil.make_archive(
        basename, "zip", base_dir=".", root_dir=input_dir, verbose=True)
463616
private static int writeGeoPackageFormatTiles(TileDao tileDao,
			File directory, String imageFormat, Integer width, Integer height,
			boolean rawImage) throws IOException {

		int tileCount = 0;

		// Go through each zoom level
		for (long zoomLevel = tileDao.getMinZoom(); zoomLevel <= tileDao
				.getMaxZoom(); zoomLevel++) {

			// Get the tile matrix at this zoom level
			TileMatrix tileMatrix = tileDao.getTileMatrix(zoomLevel);

			LOGGER.log(
					Level.INFO,
					"Zoom Level: "
							+ zoomLevel
							+ ", Width: "
							+ tileMatrix.getMatrixWidth()
							+ ", Height: "
							+ tileMatrix.getMatrixHeight()
							+ ", Max Tiles: "
							+ (tileMatrix.getMatrixWidth() * tileMatrix
									.getMatrixHeight()));

			File zDirectory = new File(directory, String.valueOf(zoomLevel));

			int zoomCount = 0;

			// Query for all tiles at the zoom level
			TileResultSet tileResultSet = tileDao.queryForTile(zoomLevel);

			while (tileResultSet.moveToNext()) {

				TileRow tileRow = tileResultSet.getRow();

				if (tileRow != null) {

					// Get the image bytes
					byte[] tileData = tileRow.getTileData();

					if (tileData != null) {

						// Make any needed directories for the image
						File xDirectory = new File(zDirectory,
								String.valueOf(tileRow.getTileColumn()));
						xDirectory.mkdirs();

						File imageFile = new File(xDirectory,
								String.valueOf(tileRow.getTileRow()) + "."
										+ imageFormat);

						if (rawImage) {

							// Write the raw image bytes to the file
							FileOutputStream fos = new FileOutputStream(
									imageFile);
							fos.write(tileData);
							fos.close();

						} else {

							// Read the tile image
							BufferedImage tileImage = tileRow
									.getTileDataImage();

							int tileWidth = width != null ? width : tileImage
									.getWidth();
							int tileHeight = height != null ? height
									: tileImage.getHeight();

							Image drawImage = null;
							if (tileImage.getWidth() != tileWidth
									|| tileImage.getHeight() != tileHeight) {
								drawImage = tileImage.getScaledInstance(
										tileWidth, tileHeight,
										Image.SCALE_SMOOTH);
							} else {
								drawImage = tileImage;
							}

							// Create the new image in the image format
							BufferedImage image = ImageUtils
									.createBufferedImage(tileWidth, tileHeight,
											imageFormat);
							Graphics graphics = image.getGraphics();

							// Draw the image
							graphics.drawImage(drawImage, 0, 0, null);

							// Write the image to the file
							ImageIO.write(image, imageFormat, imageFile);
						}

						zoomCount++;

						if (zoomCount % ZOOM_PROGRESS_FREQUENCY == 0) {
							LOGGER.log(Level.INFO, "Zoom " + zoomLevel
									+ " Tile Progress... " + zoomCount);
						}
					}
				}
			}
			tileResultSet.close();

			LOGGER.log(Level.INFO, "Zoom " + zoomLevel + " Tiles: " + zoomCount);

			tileCount += zoomCount;

		}
		return tileCount;
	}
962927
def to_wire(self, file, compress=None, origin=None, **kw):
        """"""

        return super(RRset, self).to_wire(self.name, file, compress, origin,
                                          self.deleting, **kw)
851402
def extract_rzip (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    cmdlist = [cmd, '-d', '-k']
    if verbosity > 1:
        cmdlist.append('-v')
    outfile = util.get_single_outfile(outdir, archive)
    cmdlist.extend(["-o", outfile, archive])
    return cmdlist
197924
def zip(filename, paths, strip_prefix=''):
    
    if isinstance(paths, basestring):
        paths = [paths]

    filelist = set()
    for p in paths:
        if os.path.isfile(p):
            filelist.add(p)
        else:
            for root, dirs, files in os.walk(p):
                for f in files:
                    filelist.add(os.path.join(root, f))

    z = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
    for f in sorted(filelist):
        arcname = f
        if arcname.startswith(strip_prefix):
            arcname = arcname[len(strip_prefix):]
        if arcname.startswith(os.path.sep):
            arcname = arcname[1:]
        log.debug('Adding %s to %s[%s]', f, filename, arcname)
        z.write(f, arcname)

    z.close()
335014
def execute(self, input_data):
        '''  '''
        raw_bytes = input_data['sample']['raw_bytes']
        zipfile_output = zipfile.ZipFile(StringIO(raw_bytes))
        payload_md5s = []
        for name in zipfile_output.namelist():
            filename = os.path.basename(name)
            payload_md5s.append(self.workbench.store_sample(zipfile_output.read(name), name, 'unknown'))
        return {'payload_md5s': payload_md5s}
1207118
def _to_zipfile(self, file_generator):
        
        with zipfile.ZipFile(file_generator.to_path, mode="w", compression=zipfile.ZIP_DEFLATED) as outfile:
            for f in file_generator:
                outpath = self._output_path(f.source, file_generator.to_format, archive=True)
                outfile.writestr(outpath, f.writestr(file_generator.to_format))
250674
def extract_zip(zip_name, exclude_term=None):
    """"""

    zip_dir = os.path.dirname(os.path.abspath(zip_name))

    try:
        with zipfile.ZipFile(zip_name) as z:

            # write each zipped file out if it isn't a directory
            files = [zip_file for zip_file in z.namelist() if not zip_file.endswith('/')]

            print('Extracting %i files from %r.' % (len(files), zip_name))
            for zip_file in files:

                # remove any provided extra directory term from zip file
                if exclude_term:
                    dest_file = zip_file.replace(exclude_term, '')
                else:
                    dest_file = zip_file

                dest_file = os.path.normpath(os.path.join(zip_dir, dest_file))
                dest_dir = os.path.dirname(dest_file)

                # make directory if it does not exist
                if not os.path.isdir(dest_dir):
                    os.makedirs(dest_dir)

                # read file from zip, then write to new directory
                data = z.read(zip_file)
                with open(dest_file, 'wb') as f:
                    f.write(encode_utf8(data))

    except zipfile.error as e:
        print("Bad zipfile (%r): %s" % (zip_name, e))
        raise e
906085
def open_zip(path, *args, **kwargs):
  """"""
  with contextlib.closing(PermPreservingZipFile(path, *args, **kwargs)) as zip:
    yield zip
427748
def unzip_data():
    
    with ZipFile(os.path.join(CACHE_FOLDER, CACHE_ZIP), 'r') as zf:
        zf.extractall(path=CACHE_FOLDER)
519524
def unzip_file(zip_fname):
    """""" 
    print("Unzipping {}".format(zip_fname))
    with zipfile.ZipFile(zip_fname) as zf:
        zf.extractall()
1048179
def export_input_zip(ekey, dstore):
    
    dest = dstore.export_path('input.zip')
    nbytes = dstore.get_attr('input/zip', 'nbytes')
    zbytes = dstore['input/zip'].value
    # when reading input_zip some terminating null bytes are truncated (for
    # unknown reasons) therefore they must be restored
    zbytes += b'\x00' * (nbytes - len(zbytes))
    open(dest, 'wb').write(zbytes)
    return [dest]
898050
def __zipped_files_data(self):
        """"""
        files = {}
        with zipfile.ZipFile(self.__zip_file) as thezip:
            for zipinfo in thezip.infolist():
                if zipinfo.filename.endswith('metadata/icons.json'):
                    with thezip.open(zipinfo) as compressed_file:
                        files['icons.json'] = compressed_file.read()
                elif zipinfo.filename.endswith('.ttf'):
                    # For the record, the paths usually look like this:
                    # webfonts/fa-brands-400.ttf
                    # webfonts/fa-regular-400.ttf
                    # webfonts/fa-solid-900.ttf
                    name = os.path.basename(zipinfo.filename)
                    tokens = name.split('-')
                    style = tokens[1]
                    if style in self.FA_STYLES:
                        with thezip.open(zipinfo) as compressed_file:
                            files[style] = compressed_file.read()

        # Safety checks:
        assert all(style in files for style in self.FA_STYLES), \
            'Not all FA styles found! Update code is broken.'
        assert 'icons.json' in files, 'icons.json not found! Update code is broken.'

        return files
715281
def _decompress_data(self, data):
        ''''''
        if self._decompressor:
            try:
                return self._decompressor.decompress(data)
            except zlib.error as error:
                raise ProtocolError(
                    'zlib error: {0}.'.format(error)
                ) from error
        else:
            return data