Skip to content

GZWriter

Mojo struct 🡭

@memory_only
struct GZWriter

Writer for gzip-compressed files.

  • handle (c_void_ptr)
  • lib (ZLib)
  • filename (String)
  • mode (String)

AnyType, ImplicitlyDestructible, Movable, WriterBackend

def __init__(out self, filename: String, mode: String = "wb")

Initialize GZWriter with a file path.

Args:

  • filename (String): Path to the output .gz file.
  • mode (String): File mode (default “wb” for write binary).
  • self (Self)

Returns:

Self

Raises:

Error: If the file cannot be opened for writing.

def __init__(out self, *, deinit take: Self)

Move constructor.

Args:

  • take (Self)
  • self (Self)

Returns:

Self

def __del__(deinit self)

Close the file when the object is destroyed.

Args:

  • self (Self)
def write_from_buffer(mut self, mut buf: Span[Byte, MutExternalOrigin], amt: Int, pos: Int = 0) -> UInt64

Write bytes from buffer to compressed file.

Args:

  • self (Self)
  • buf (Span)
  • amt (Int)
  • pos (Int)

Returns:

UInt64

Raises: