Extracts a file from a bytes_io zip. Returns bytes
552882
def extract_file_from_zip(bytes_io, expected_file):
    """"""
    zipf = zipfile.ZipFile(bytes_io) 
    return zipf.read(expected_file)
251556
def extract(context, data):
    """"""
    with context.http.rehash(data) as result:
        file_path = result.file_path
        content_type = result.content_type
        extract_dir = random_filename(context.work_path)
        if content_type in ZIP_MIME_TYPES:
            extracted_files = extract_zip(file_path, extract_dir)
        elif content_type in TAR_MIME_TYPES:
            extracted_files = extract_tar(file_path, extract_dir, context)
        elif content_type in SEVENZIP_MIME_TYPES:
            extracted_files = extract_7zip(file_path, extract_dir, context)
        else:
            context.log.warning(
                "Unsupported archive content type: %s", content_type
            )
            return
        extracted_content_hashes = {}
        for path in extracted_files:
            relative_path = os.path.relpath(path, extract_dir)
            content_hash = context.store_file(path)
            extracted_content_hashes[relative_path] = content_hash
            data['content_hash'] = content_hash
            data['file_name'] = relative_path
            context.emit(data=data.copy())
826513
def extract_lzma(archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return _extract(archive, compression, cmd, 'alone', verbosity, outdir)
1229735
def get_contents_from_zip zip_file
        contents = {}
        Zip::File.open(zip_file) do |zip|
          zip.each_entry do |entry|
            entry.get_input_stream do |entryfile|
              contents[entry.name] = entryfile.read
            end
          end
        end
        return contents
      end
144709
def extract_data(filename, num_images):
  
  print('Extracting', filename)
  with gzip.open(filename) as bytestream:
    bytestream.read(16)
    buf = bytestream.read(IMAGE_SIZE * IMAGE_SIZE * num_images)
    data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
    data = (data - (PIXEL_DEPTH / 2.0)) / PIXEL_DEPTH
    data = data.reshape(num_images, IMAGE_SIZE, IMAGE_SIZE, 1)
    return data
626146
def extract_bzip2 (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    targetname = util.get_single_outfile(outdir, archive)
    try:
        with bz2.BZ2File(archive) as bz2file:
            with open(targetname, 'wb') as targetfile:
                data = bz2file.read(READ_SIZE_BYTES)
                while data:
                    targetfile.write(data)
                    data = bz2file.read(READ_SIZE_BYTES)
    except Exception as err:
        msg = "error extracting %s to %s: %s" % (archive, targetname, err)
        raise util.PatoolError(msg)
    return None
1357239
def get_gzipped_contents(input_file):
    
    zbuf = StringIO()
    zfile = GzipFile(mode="wb", compresslevel=6, fileobj=zbuf)
    zfile.write(input_file.read())
    zfile.close()
    return ContentFile(zbuf.getvalue())
697738
public File extractZipEntry(File dir, ZipFile zipFile, ZipEntry entry) throws IOException {
    File outputFile = new File(dir, entry.getName());
    File parentFile = outputFile.getParentFile();
    if (!outputFile.getCanonicalPath().startsWith(dir.getCanonicalPath() + File.separator)
        || (!parentFile.isDirectory() && !parentFile.mkdirs())) {
      throw new IOException("Could not extract " + entry.getName() + " to " + dir.getPath());
    }
    try (InputStream inputStream = zipFile.getInputStream(entry);
        FileOutputStream outputStream = new FileOutputStream(outputFile)) {
      byte[] buf = new byte[1024];
      int n;
      while ((n = inputStream.read(buf)) > 0) {
        outputStream.write(buf, 0, n);
      }
    }
    return outputFile;
  }
265624
def extract
      Zip::File.open(package_file) do |zip|
        batch_size = [1, (zip.size / 100).to_i].max
        dots = 0
        zip.each do |file|
          @output.print "." if (dots % batch_size).zero?
          file.restore_permissions = true
          file.extract { accept_all }
          dots += 1
        end
      end
    end
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
1087885
def get_zip_content(self, filename):
        """"""

        with zipfile.ZipFile(filename, 'r') as z:
            self.determine_file_type(z)
            for item in z.infolist():
                if glob.globmatch(item.filename, self.filepattern, flags=self.FLAGS):
                    yield z.read(item.filename), item.filename
1197250
private ByteBuffer getChunk(final int chunkIdx) throws IOException, InterruptedException {
        ByteBuffer chunk = chunkCache[chunkIdx];
        if (chunk == null) {
            final ByteBuffer byteBufferDup = zipFileSlice.physicalZipFile.getByteBuffer(chunkIdx).duplicate();
            chunk = chunkCache[chunkIdx] = byteBufferDup;
        }
        return chunk;
    }
996804
def from_bytes(self, bytes_representation, resource=None):
        
        text = bytes_representation.decode(self.encoding)
        return self.from_string(text, resource=resource)
381219
def zipentry_chunk(zipfile, name, size=_BUFFERING):
    

    def chunks():
        with zipfile.open(name) as fd:
            buf = fd.read(size)
            while buf:
                yield buf
                buf = fd.read(size)
    return chunks
594058
def get_filelikeobject(filename: str = None,
                       blob: bytes = None) -> BinaryIO:
    
    if not filename and not blob:
        raise ValueError("no filename and no blob")
    if filename and blob:
        raise ValueError("specify either filename or blob")
    if filename:
        return open(filename, 'rb')
    else:
        return io.BytesIO(blob)
158541
def of_bytes(self, py_bytes):
        
        m = self.hash_algo()
        m.update(py_bytes)
        return self.digest(m)
822199
def from_zipfile(cls, path, filename, encoding, dialect, fields, converters):
        """"""

        stream = ZipReader(path, filename).readlines(encoding)
        return cls(stream, dialect, fields, converters)