Podium.OPC.Package (Podium v0.3.0)

Copy Markdown View Source

OPC (Open Packaging Convention) ZIP package read/write operations.

Reads and writes .pptx files as ZIP archives containing XML parts and binary resources. Each part is represented as a %{path => binary} map.

Summary

Functions

Reads a .pptx file from disk and returns a map of %{path => binary}.

Reads a .pptx from an in-memory ZIP binary and returns a map of %{path => binary}.

Reads the default.pptx template bundled with the library.

Reads a .pptx from either a filesystem path or a ZIP binary.

Resolves a relationship target against the partname of the part that owns the relationship, returning a canonical package partname.

Writes a map of %{path => binary} as a .pptx (ZIP) file.

Writes a map of parts to an in-memory ZIP binary.

Functions

read(path)

@spec read(String.t()) ::
  {:ok, %{required(String.t()) => binary()}} | {:error, term()}

Reads a .pptx file from disk and returns a map of %{path => binary}.

read_binary(binary)

@spec read_binary(binary()) ::
  {:ok, %{required(String.t()) => binary()}} | {:error, term()}

Reads a .pptx from an in-memory ZIP binary and returns a map of %{path => binary}.

read_default_template()

@spec read_default_template() ::
  {:ok, %{required(String.t()) => binary()}} | {:error, term()}

Reads the default.pptx template bundled with the library.

read_source(binary)

@spec read_source(binary()) ::
  {:ok, %{required(String.t()) => binary()}} | {:error, term()}

Reads a .pptx from either a filesystem path or a ZIP binary.

A binary starting with the ZIP local file header signature (PK\x03\x04) is treated as pptx bytes; anything else is treated as a path.

resolve_partname(owner_partname, target)

@spec resolve_partname(String.t(), String.t()) :: String.t()

Resolves a relationship target against the partname of the part that owns the relationship, returning a canonical package partname.

Targets are relative to the owning part's folder, so the same slide master is slideMasters/slideMaster1.xml from ppt/presentation.xml and ../slideMasters/slideMaster1.xml from a slide layout. A target starting with / is already absolute from the package root.

iex> Podium.OPC.Package.resolve_partname("ppt/presentation.xml", "slideMasters/slideMaster1.xml")
"ppt/slideMasters/slideMaster1.xml"

iex> Podium.OPC.Package.resolve_partname("ppt/slideLayouts/slideLayout1.xml", "../slideMasters/slideMaster1.xml")
"ppt/slideMasters/slideMaster1.xml"

iex> Podium.OPC.Package.resolve_partname("ppt/slideLayouts/slideLayout1.xml", "/ppt/media/logo.png")
"ppt/media/logo.png"

write(parts, output_path)

@spec write(%{required(String.t()) => binary()}, String.t()) :: :ok | {:error, term()}

Writes a map of %{path => binary} as a .pptx (ZIP) file.

write_to_memory(parts)

@spec write_to_memory(%{required(String.t()) => binary()}) ::
  {:ok, binary()} | {:error, term()}

Writes a map of parts to an in-memory ZIP binary.