zipbeam
Bindings to Erlang’s zip module.
gleam add zipbeam@1
import zipbeam
pub fn create_zip() -> BitArray {
// Create a zip archive with a couple of files in it
zipbeam.new()
|> zipbeam.add_file("a", <<1, 2, 3>>)
|> zipbeam.add_file("b", <<2, 3>>)
|> zipbeam.create_in_memory
}
pub fn open_zip(zip: BitArray) -> Nil {
// Open the zip archives
let assert Ok(handle) = zipbeam.open(zip)
// List the files inside. You must always check they are the size you expect
// before extracting the content, to prevent zip-bomb attacks.
assert zipbeam.files(handle)
== Ok([
zipbeam.File(path: "nubi.jpg", size_bytes: 12_440),
zipbeam.File(path: "oshii.jpg", size_bytes: 20_278),
])
// Get files
let assert Ok(_data) = zipbeam.get(handle, "oshii.jpg")
}
Documentation can be found at https://hexdocs.pm/zipbeam.