Packmatic v0.1.0 Packmatic.Encoder View Source

Holds logic which can be used to put together a ZIP file in an interative fashion, suitable for wrapping within a Stream. The format of ZIP files emitted by Packmatic.Encoder is documented under the modules implementing the Packmatic.Field protocol.

The Encoder is wrapped in Stream.resource/3 for consumption as an Elixir Stream, under Packmatic.build_stream/1. Further, the Stream can be used with Plug.Conn to serve a chunked connection easily, as provided in Packmatic.Conn.send_chunked/3.

The Encoder has three statuses:

  1. Encoding, where each Entry within the Manifest is transformed to a Source, which is subsequently consumed.

    If the on_error option is set to :skip when building the stream, then sources which have raised error are skipped, although at this time portions of the source may have already been sent. Otherwise, and as the default behaviour, an uncaught exception will be raised and the consumer of the Stream will crash.

    During Encoding, content is dynamically deflated.

  2. Journaling, where each successfully encoded Entry is journaled again at the end of the archive, with the Central Directory structure.

    Both Zip and Zip64 formats are used for maximum flexibility.

    In case the on_error option is set to :skip, any source which has raised an error during its consumption will not be journaled. Due to the nature of streaming archives, this may still leave portions of unusable data within the archive.

  3. Done, which is the terminal status.

Link to this section Summary

Functions

Iterates the Stream.

Starts the Stream by validating the Manifest and initialising the Encoding State.

Link to this section Types

Link to this type

error()

View Source
error() :: {:error, term()}
Link to this type

ok_done()

View Source
ok_done() :: {:ok, iolist(), :done, nil}
Link to this type

ok_encoding()

View Source
ok_encoding() :: {:ok, iolist(), :encoding, state_encoding()}
Link to this type

ok_halt()

View Source
ok_halt() :: {:ok, :halt, :done, nil}
Link to this type

ok_journaling()

View Source
ok_journaling() :: {:ok, iolist(), :journaling, state_journaling()}
Link to this type

ok_start_encoding()

View Source
ok_start_encoding() :: {:ok, :encoding, state_encoding()}
Link to this type

options()

View Source
options() :: [{:on_error, :skip | :halt}]
Link to this type

state_encoding()

View Source
state_encoding() :: Packmatic.Encoder.EncodingState.t()
Link to this type

state_journaling()

View Source
state_journaling() :: Packmatic.Encoder.JournalingState.t()

Link to this section Functions

See :erlang.iolist_size/1.

Link to this function

stream_after(_, _)

View Source
stream_after(:done, nil) :: :ok
Link to this function

stream_next(arg1, state)

View Source
stream_next(:encoding, state_encoding()) ::
  ok_encoding() | ok_journaling() | error()
stream_next(:journaling, state_journaling()) :: ok_journaling() | ok_done()
stream_next(:done, nil) :: ok_halt()

Iterates the Stream.

When the Stream is in :encoding status, this function may continue encoding of the current item, or advance to the next item, or advance to the :journaling status when there are no further items to encode.

When the Stream is in :journaling status, this function may continue journaling the next item, or advance to the :done status.

When the Stream is in :done status, it can not be iterated further.

Link to this function

stream_start(manifest, options)

View Source
stream_start(manifest(), options()) :: ok_start_encoding() | {:error, term()}

Starts the Stream by validating the Manifest and initialising the Encoding State.