Add file contents to the archive under ``dest``.

        If ``dest`` is a path, it will be added compressed and world-readable
        (user-writeable). You may also pass a :py:class:`~zipfile.ZipInfo` for
        custom behavior.
963382
def add_contents(self, dest, contents):
        
        assert not self._closed, "Archive closed"
        if not isinstance(dest, zipfile.ZipInfo):
            dest = zinfo(dest)  # see for some caveats
        # Ensure we apply the compression
        dest.compress_type = self.zip_compression
        # Mark host OS as Linux for all archives
        dest.create_system = 3
        self._zip_file.writestr(dest, contents)
827545
def extract_zipfile(archive_name, destpath):
    ""
    archive = zipfile.ZipFile(archive_name)
    archive.extractall(destpath)
65986
def zip_file(fn, mode="r"):
    

    if isdir(fn):
        return ExplodedZipFile(fn)
    elif is_zipfile(fn):
        return ZipFile(fn, mode)
    else:
        raise Exception("cannot treat as an archive: %r" % fn)
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))
759366
private void addFile(File root, File file, String prefix, ZipOutputStream zos) throws IOException {
        FileInputStream fis = new FileInputStream(file);
        ZipEntry jarEntry = new ZipEntry(prefix + normalizePath(root, file));
        zos.putNextEntry(jarEntry);
        StreamUtils.copyStream(fis, zos, false);
        fis.close();
    }
688441
def compress_to(self, archive_path=None):
        
        if archive_path is None:
            archive = tempfile.NamedTemporaryFile(delete=False)
            tar_args = ()
            tar_kwargs = {'fileobj': archive}
            _return = archive.name
        else:
            tar_args = (archive_path)
            tar_kwargs = {}
            _return = archive_path
        tar_kwargs.update({'mode': 'w:gz'})
        with closing(tarfile.open(*tar_args, **tar_kwargs)) as tar:
            tar.add(self.path, arcname=self.file)

        return _return
1077910
def add_file(self, git_path, content):
        
        blob_id = self.write_blob(content)
        self.add_index('100644', blob_id, git_path)
764577
def archive(self, target_path=None, zip_path=None):
        
        if target_path:
            self.target_path = target_path

        if zip_path:
            self.zip_path = zip_path

        if self.has_path is False or os.path.isdir(self.target_path) is False:
            raise RuntimeError("")

        zip = zipfile.ZipFile(
            self.zip_path,
            'w',
            zipfile.ZIP_DEFLATED
        )

        for root, _, files in os.walk(self.target_path):
            for file in files:
                if file in ARCHIVE_IGNORE_FILES:
                    continue

                current_dir = os.path.relpath(root, self.target_path)

                if current_dir == ".":
                    file_path = file
                else:
                    file_path = os.path.join(current_dir, file)

                print("Archive {}".format(file))

                zip.write(
                    os.path.join(root, file),
                    file_path
                )

        zip.close()
1355821
def add_to_archive(self, spec):
        '''
        
        '''
        if isinstance(spec, InsightsCommand):
            archive_path = os.path.join(self.cmd_dir, spec.archive_path.lstrip('/'))
        if isinstance(spec, InsightsFile):
            archive_path = self.get_full_archive_path(spec.archive_path.lstrip('/'))
        output = spec.get_output()
        if output:
            write_data_to_file(output, archive_path)
259433
public static void addEntry(File zip, String path, File file, File destZip) {
    addEntry(zip, new FileSource(path, file), destZip);
  }
724376
def file_put_contents(path, data):
    
    with open(path, 'w') as f:
        f.write(data); f.flush()
902825
def create_zip_from_folder(zip_file, fldr, mode="r"):
    
    #print('zip from folder - adding folder : ', fldr)
    zipf = zipfile.ZipFile(zip_file, 'w')
    for root, dirs, files in os.walk(fldr):
        for file in files:
            fullname = os.path.join(root, file)
            #print('zip - adding file : ', fullname)
            zipf.write(fullname)
    
    
    zipf.close()
1090420
def _add_file(self, key, path):
        """"""
        filename = os.path.basename(path)
        base, ext = os.path.splitext(filename)
        if os.path.exists(self.file_path(filename)):
            with tempfile.NamedTemporaryFile(
                    dir=self.path, prefix=base, suffix=ext) as tf:
                filename = os.path.basename(tf.name)
        shutil.copyfile(path, self.file_path(filename))
        self.contents['files'][key] = filename
1032554
def _write_to_zip(self, path, contents):
        
        if isinstance(path, list):
            path = os.path.sep.join(path)
        self.zf.writestr(path, contents)
285911
def _generate_tar(dir_path):
    """"""
    try:
        with tarfile.open(dir_path + '.tar', 'w') as tar:
            tar.add(dir_path)
    except tarfile.TarError as e:
        stderr("Error: tar archive creation failed [" + str(e) + "]", exit=1)
625536
def addarchive(self, name):
        
        with tarfile.open(name, 'r') as st:
            for member in st.getmembers():
                self.tarfile.addfile(member, st.extractfile(member.name))
1332477
def AddFileReadData(self, path, file_data_path):
    
    if self.file_system.FileEntryExistsByPath(path):
      raise ValueError('Path: {0:s} already set.'.format(path))

    with open(file_data_path, 'rb') as file_object:
      file_data = file_object.read()

    self._AddParentDirectories(path)
    self.file_system.AddFileEntry(path, file_data=file_data)