Skip to content

GZWriter

Mojo struct 🡭

@memory_only
struct GZWriter

Writer for gzip-compressed files.

  • handle (Optional[Pointer[UInt8, ImmUntrackedOrigin]])
  • lib (ZLib)
  • filename (String)
  • mode (String)

AnyType, Deinitable, Movable, WriterBackend

fn 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.

fn def __init__(out self, *, deinit move: Self)

Move constructor.

Args:

  • move (Self)
  • self (Self)

Returns:

Self

fn def __deinit__(deinit self)

Close the file when the object is destroyed.

Args:

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

Write bytes from buffer to compressed file.

Args:

  • self (Self)
  • buf (Span[UInt8, MutUntrackedOrigin])
  • amt (Int)
  • pos (Int)

Returns:

UInt64

Raises: