CompoundFile.Writer (compound_file v0.1.0)
View SourceCreates a Compound File Document (CFD) in the Microsoft Compound File Binary Format (CFBF).
This module allows you to create a new document, add streams and storages, and render the final binary representation of the document.
Example usage
iex> alias CompoundFile.Writer
iex>
iex> Writer.new()
iex> |> Writer.add_file("example.txt", "Hello, World!")
iex> |> Writer.add_file("data/text/example2.txt", "Another file")
iex> |> Writer.render()
This will create a new Compound File Document with the following files:
/example.txt
/data/text/example2.txt
Summary
Functions
Adds a file to the Compound File Document.
Adds a storage object (directory) to the Compound File Document.
Adds a stream object to the Compound File Document.
Initialises a new, empty Compound File Document.
Renders the Compound File Document to a binary format.
Functions
@spec add_file(CompoundFile.Writer.Document.t(), String.t(), binary()) :: CompoundFile.Writer.Document.t()
Adds a file to the Compound File Document.
If the directory structure specified in the path
does not exist, directories (storage objects)
will be created as needed. The file will then be added as a stream object.
Returns the updated document.
@spec add_storage( CompoundFile.Writer.Document.t(), non_neg_integer() | nil, String.t() ) :: {CompoundFile.Writer.Document.t(), object_id :: pos_integer()}
Adds a storage object (directory) to the Compound File Document.
This function creates a new storage entry in the document. The storage object can be used to group
files (stream objects) together. The parent
parameter specifies the parent storage object ID, or
nil
for the root directory. The filename
is the name of the storage object.
Returns a tuple of the updated document and the object ID of the new storage object.
@spec add_stream( CompoundFile.Writer.Document.t(), non_neg_integer() | nil, String.t(), binary() ) :: CompoundFile.Writer.Document.t()
Adds a stream object to the Compound File Document.
This function is used to add a binary stream to the document. The stream object is added to the
either the root directory (when parent
is nil
) or to the specified parent directory (by
passing the storage object's ID as parent
).
Returns the updated document.
@spec new() :: CompoundFile.Writer.Document.t()
Initialises a new, empty Compound File Document.
@spec render(CompoundFile.Writer.Document.t()) :: {:ok, binary()} | {:error, :empty | :file_size_limit_exceeded | :filename_too_long}
Renders the Compound File Document to a binary format.
Returns {:ok, binary()}
containing the complete binary representation of the document.
You can write this binary to a file or use it as needed.