zipbeam

Types

A file within a zip archive.

pub type File {
  File(path: String, size_bytes: Int)
}

Constructors

  • File(path: String, size_bytes: Int)
pub opaque type ZipBuilder

A reference to an open zip archive, returned by open.

pub type ZipHandle

Values

pub fn add_file(
  builder: ZipBuilder,
  at path: String,
  containing contents: BitArray,
) -> ZipBuilder

Add a file to the builder, to be included in the zip archive.

pub fn close(handle: ZipHandle) -> Nil

Close the handle.

pub fn create_in_memory(builder: ZipBuilder) -> BitArray

Create a zip archive.

pub fn files(handle: ZipHandle) -> Result(List(File), Nil)

List the files in the zip archive, including their uncompressed sized.

Returns an error if the handle has already been closed.

pub fn get(
  handle: ZipHandle,
  path: String,
) -> Result(BitArray, Nil)

Get a file from the archive.

Security

You must always check the size of the file with files before extracting a file, to prevent zip-bomb attacks.

pub fn new() -> ZipBuilder
pub fn open(zip: BitArray) -> Result(ZipHandle, Nil)

Open a zip archive. Returns an error if the data given could not be parsed as a zip archive.

The archive must be closed with close.

The handle is closed if the process that originally opened the archive dies.

Search Document