Dumps the given resource and all resources linked to it into the given
        ZIP file.
4650
def to_zipfile(self, resource, zipfile):
        
        rpr_map = self.to_strings(resource)
        with ZipFile(zipfile, 'w') as zipf:
            for (mb_cls, rpr_string) in iteritems_(rpr_map):
                fn = get_collection_filename(mb_cls, self.__content_type)
                zipf.writestr(fn, rpr_string, compress_type=ZIP_DEFLATED)
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)
781610
protected void writeEntries(final StorageAwareResource resource, final ZipOutputStream zipOut) throws IOException {
    final BufferedOutputStream bufferedOutput = new BufferedOutputStream(zipOut);
    ZipEntry _zipEntry = new ZipEntry("emf-contents");
    zipOut.putNextEntry(_zipEntry);
    try {
      this.writeContents(resource, bufferedOutput);
    } finally {
      bufferedOutput.flush();
      zipOut.closeEntry();
    }
    ZipEntry _zipEntry_1 = new ZipEntry("resource-description");
    zipOut.putNextEntry(_zipEntry_1);
    try {
      this.writeResourceDescription(resource, bufferedOutput);
    } finally {
      bufferedOutput.flush();
      zipOut.closeEntry();
    }
    if (this.storeNodeModel) {
      ZipEntry _zipEntry_2 = new ZipEntry("node-model");
      zipOut.putNextEntry(_zipEntry_2);
      try {
        this.writeNodeModel(resource, bufferedOutput);
      } finally {
        bufferedOutput.flush();
        zipOut.closeEntry();
      }
    }
  }
600785
private function copyToOutputAndCleanup($output, $zipFileUrl)
    {
        $zipFilePointer = fopen($zipFileUrl, 'r');
        if (!stream_copy_to_stream($zipFilePointer, $output)
            || !fclose($zipFilePointer)
            || !fclose($output)
            || !unlink($zipFileUrl)
        ) {
            throw new \RuntimeException("Failed to copy stream and clean up!");
        }
    }
805893
def CopyFileInZip(from_zip, from_name, to_zip, to_name=None):
  """"""
  data = from_zip.read(from_name)
  if to_name is None:
    to_name = from_name
  to_zip.writestr(to_name, data)
466617
def zipFile(source):
    
    # source = source.decode('UTF-8')
    target = source[0:source.rindex(".")] + '.zip'
    try:
        with zipfile.ZipFile(target, 'w') as zip_file:
            zip_file.write(source, source[source.startswith('/'):], zipfile.ZIP_DEFLATED)
            zip_file.close()
            __cps_rate__(source, target)
    except IOError as e:
        logger.error('Compress file[%s] with zip mode failed. Case: %s', source, str(e))
        target = source

    return target
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();
      }
   }
1303716
protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException {
    zipIn.getNextEntry();
    BufferedInputStream _bufferedInputStream = new BufferedInputStream(zipIn);
    this.readContents(resource, _bufferedInputStream);
    zipIn.getNextEntry();
    BufferedInputStream _bufferedInputStream_1 = new BufferedInputStream(zipIn);
    this.readResourceDescription(resource, _bufferedInputStream_1);
    if (this.storeNodeModel) {
      zipIn.getNextEntry();
      BufferedInputStream _bufferedInputStream_2 = new BufferedInputStream(zipIn);
      this.readNodeModel(resource, _bufferedInputStream_2);
    }
  }
1045846
public static void extract(int format, Resource[] sources, Resource target) throws IOException {
	if (format == FORMAT_ZIP || format == FORMAT_TAR) {
	    for (int i = 0; i < sources.length; i++) {
		extract(format, sources[i], target);
	    }
	}
	else throw new IOException("can't extract in given format");
    }
1196258
static void createFileFromResource(String resource, Resource file, String password) throws IOException {
	SystemOut.printDate(SystemUtil.getPrintWriter(SystemUtil.OUT), "write file:" + file);
	file.delete();

	InputStream is = InfoImpl.class.getResourceAsStream(resource);
	if (is == null) throw new IOException("file [" + resource + "] does not exist.");
	file.createNewFile();
	IOUtil.copy(is, file, true);
    }
272312
public static void zipDirectory(Logger log, File directory, ZipOutputStream zos, String path, FileFilter filter) throws IOException {
        // get a listing of the directory content
        File[] dirList = directory.listFiles();
        byte[] readBuffer = new byte[8192];
        int bytesIn = 0;
        // loop through dirList, and zip the files
        if (dirList != null) {
            for (File f : dirList) {
                if (f.isDirectory()) {
                    String prefix = path + f.getName() + "/";
                    if (matches(filter, f)) {
                        zos.putNextEntry(new ZipEntry(prefix));
                        zipDirectory(log, f, zos, prefix, filter);
                    }
                } else {
                    String entry = path + f.getName();
                    if (matches(filter, f)) {
                        FileInputStream fis = new FileInputStream(f);
                        try {
                            ZipEntry anEntry = new ZipEntry(entry);
                            zos.putNextEntry(anEntry);
                            bytesIn = fis.read(readBuffer);
                            while (bytesIn != -1) {
                                zos.write(readBuffer, 0, bytesIn);
                                bytesIn = fis.read(readBuffer);
                            }
                        } finally {
                            fis.close();
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("zipping file " + entry);
                        }
                    }
                }
                zos.closeEntry();
            }
        }
    }
852512
def copy_resource(src, dest):
    
    package_name = "yass"
    dest = (dest + "/" + os.path.basename(src)).rstrip("/")
    if pkg_resources.resource_isdir(package_name, src):
        if not os.path.isdir(dest):
            os.makedirs(dest)
        for res in pkg_resources.resource_listdir(__name__, src):
            copy_resource(src + "/" + res, dest)
    else:
        if not os.path.isfile(dest) \
                and os.path.splitext(src)[1] not in [".pyc"]:
            with open(dest, "wb") as f:
                f.write(pkg_resources.resource_string(__name__, src))
        else:
            print("File exists: %s " % dest)
392067
def __save_output(self):
        
        out = zipfile.ZipFile(self.outputfilename, 'w')

        for info_zip in self.infile.infolist():

            if info_zip.filename in self.templated_files:
                # Template file - we have edited these.

                # get a temp file
                streamout = open(get_secure_filename(), "w+b")
                fname, output_stream = self.output_streams[
                    self.templated_files.index(info_zip.filename)
                ]

                transformer = get_list_transformer(self.namespaces)
                remapped_stream = output_stream | transformer

                # write the whole stream to it
                for chunk in remapped_stream.serialize():
                    streamout.write(chunk.encode('utf-8'))
                    yield True

                # close the temp file to flush all data and make sure we get
                # it back when writing to the zip archive.
                streamout.close()

                # write the full file to archive
                out.write(streamout.name, fname)

                # remove temp file
                os.unlink(streamout.name)

            else:
                # Copy other files straight from the source archive.
                out.writestr(info_zip, self.infile.read(info_zip.filename))

        # Save images in the "Pictures" sub-directory of the archive.
        for identifier, data in self.images.items():
            out.writestr(PY3O_IMAGE_PREFIX + identifier, data)

        # close the zipfile before leaving
        out.close()
        yield True
680352
public function zipResourceFile($file, $resource)
    {
        if (!$this->zip->addFromString($file, json_encode($resource, JSON_UNESCAPED_SLASHES))) {
            throw new InternalServerErrorException("Failed to add $file to the Zip Archive.");
        }
    }
679623
public void unzipArchive(String file, File outputDir)
      throws IOException {

    try (ZipFile zipFile = new ZipFile(file)) {

      final Enumeration<? extends ZipEntry> entries = zipFile.entries();
      while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final File entryDestination = new File(outputDir, entry.getName());
        if (!org.apache.gobblin.util.FileUtils.isSubPath(outputDir, entryDestination)) {
          throw new IOException(String.format("Extracted file: %s is trying to write outside of output directory: %s",
              entryDestination, outputDir));
        }

        if (entry.isDirectory()) {
          // If entry is directory, create directory
          if (!entryDestination.mkdirs() && !entryDestination.exists()) {
            throw new IOException("Could not create directory: " + entryDestination
                + " while un-archiving zip: " + file);
          }
        } else {
          // Create parent dirs if required
          if (!entryDestination.getParentFile().mkdirs() && !entryDestination.getParentFile().exists()) {
            throw new IOException("Could not create parent directory for: " + entryDestination
                + " while un-archiving zip: " + file);
          }

          // Extract and save the conf file
          InputStream in = null;
          OutputStream out = null;
          try {
            in = zipFile.getInputStream(entry);
            out = new FileOutputStream(entryDestination);
            IOUtils.copy(in, out);
          } finally {
            if (null != in)
              IOUtils.closeQuietly(in);
            if (null != out)
              IOUtils.closeQuietly(out);
          }
        }
      }
    }
  }
899414
private void writeZipFile() {

        try {
            FileOutputStream fos = new FileOutputStream(ZIP_PATH);
            ZipGenerator zipGen = new ZipGenerator(fos);
            for (File file : CmsLogFileOptionProvider.getLogFiles()) {
                if (!file.isDirectory() & !ZIP_PATH.equals(file.getAbsolutePath())) {
                    zipGen.addToZip(new File(CmsLogFileApp.LOG_FOLDER), file);
                }
            }
            zipGen.close();
            fos.close();

        } catch (IOException e) {
            LOG.error("unable to build zip file", e);
        }
    }
876353
public void addAllSubsystemFileSourcesFromZipFile(File file) throws IOException {
        try (ZipFile zip = new ZipFile(file)) {
            // extract subsystem template and schema, if present
            if (zip.getEntry("subsystem-templates") != null) {
                Enumeration<? extends ZipEntry> entries = zip.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = entries.nextElement();
                    if (!entry.isDirectory()) {
                        String entryName = entry.getName();
                        if (entryName.startsWith("subsystem-templates/")) {
                            addSubsystemFileSource(entryName.substring("subsystem-templates/".length()), file, entry);
                        }
                    }
                }
            }
        }
    }