Sablon.Zip (sablon v0.4.4)

Copy Markdown View Source

A minimal in-memory ZIP reader and writer.

A .docx file is an OPC package, i.e. a ZIP archive, and rendering a template means reading every entry, rewriting some of them and writing the archive back out. Entry order is preserved on the way through because Word expects [Content_Types].xml to come first.

Summary

Functions

Reads every file entry of archive, in central directory order.

Reads path from disk and returns its entries.

Builds an archive from entries, a list of {name, content} pairs in the order they should be stored.

Writes an archive built from entries to path.

Types

entry()

@type entry() :: {binary(), binary()}

Functions

read(archive)

@spec read(binary()) :: [entry()]

Reads every file entry of archive, in central directory order.

Directory entries are skipped; only files are returned.

read_file(path)

@spec read_file(Path.t()) :: [entry()]

Reads path from disk and returns its entries.

write(entries)

@spec write([entry()]) :: binary()

Builds an archive from entries, a list of {name, content} pairs in the order they should be stored.

Intermediate directory entries are created automatically, which keeps Word happy for packages that reference files across folders.

write_file(path, entries)

@spec write_file(Path.t(), [entry()]) :: :ok

Writes an archive built from entries to path.