Work with files and directories in the archive.
Extract the content of an Entry as a String.
Extract the content of an Entry as Bytes.
Bytes can represent an image, a PDF, a ZIP within a ZIP, anything you can imagine.
Examples of what you can do with Bytes:
File.Download.bytes to download them as a file.Http.bytesBody to send them to an HTTP server.elm/bytes package to decode these bytes into any data structure.Extracting content from an entry might fail if:
The data is compressed through an unsupported method. See extractWith for more information.
The extracted data does not match the integrity checksum.
The entry has no data of the expected type.
The DEFLATE data is corrupted.
Get the absolute path of an entry.
path dir == "versions/"
path v1 == "versions/v1.txt"
path v2 == "versions/v2.txt"Even though Zip archives are aware of directories, they do not store entries in a tree format. Instead, each entry simply indicates its absolute path in the archive.
Different applications have different needs and they may or may not care about the tree structure.
Some applications might expect a certain structure and can simply use Zip.byPath to get the
relevant entries.
Other applications might want to explore the archive, and can use Zip.ls to get a list of the entries and go from there.
Get the uncompressed size of an entry.
This is the number of bytes that you will get if you extract this entry.
Get the compressed size of an entry as stored in the archive.
Get the last time an entry was modified.
Zip time stamps are relative to the time zone they were created in.
Unfortunately, this information is not stored anywhere, making them only meaningful if you know it.
Determine whether an entry is a directory.
Get the comment of an entry.
Did you know files can have comments? I didn't.
Get the CRC32 checksum of an entry's uncompressed data.
You do not need to confirm the integrity of data manually. The extract content functions perform this check automatically for you.
However, you might still find this checksum useful for other purposes, like quickly determining whether two files are identical.
This library uses the folkertdev/elm-flate package to support
Deflate compression. Most archives you'll find in the wild will use this method.
If you're expecting to work with archives using other methods, you can use the following function to handle them.
Extract archives with other compression methods.
handleCompression { method, rawBytes } =
case method of
6 ->
-- Use raw bytes to extract the data.
decodeImplode rawBytes
_ ->
-- We don't know how to handle other methods.
Nothing
extracted =
entry |> extractWith handleCompressionNote: This callback is only called if the method is not 0 (Stored) nor 8 (Deflated). You do not need to handle these yourself.
You can read more about compression methods and their corresponding numbers in section 4.4.5 of the specification.
Represents a file or a directory in a
Ziparchive.You can use this to extract the content and read the metadata.
Check out Entry.path to learn more about the way these entries are stored.