bcf.inmemory_zipfile

In Memory Zip File management, taken from ruamel.std.zipfile

Copyright (c) 2017-2020 Anthon van der Neut, Ruamel bvba

original idea from https://stackoverflow.com/a/19722365/1307905

Module Contents

class bcf.inmemory_zipfile.InMemoryZipFile(file_name: str | pathlib.Path | None = None, compression: int = zipfile.ZIP_DEFLATED, debug: int = 0)
property data: bytes
write_to_file(filename: str | bytes | os.PathLike[str] | os.PathLike[bytes] | int) None

Writes the in-memory zip to a file.

writestr(filename_in_zip: str | zipfile.ZipInfo, file_contents: bytes | str) None

Appends a file with name filename_in_zip and contents of file_contents to the in-memory zip.

class bcf.inmemory_zipfile.ZipFileInterface

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
writestr(filename_in_zip: str | zipfile.ZipInfo, file_contents: bytes | str) None