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:
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.
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.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
ok_encoding()
View Sourceok_encoding() :: {:ok, iolist(), :encoding, state_encoding()}
ok_journaling()
View Sourceok_journaling() :: {:ok, iolist(), :journaling, state_journaling()}
ok_start_encoding()
View Sourceok_start_encoding() :: {:ok, :encoding, state_encoding()}
state_encoding()
View Sourcestate_encoding() :: Packmatic.Encoder.EncodingState.t()
state_journaling()
View Sourcestate_journaling() :: Packmatic.Encoder.JournalingState.t()
Link to this section Functions
stream_next(arg1, state)
View Sourcestream_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.
stream_start(manifest, options)
View Sourcestream_start(manifest(), options()) :: ok_start_encoding() | {:error, term()}
Starts the Stream by validating the Manifest and initialising the Encoding State.