ICouch v0.5.0 ICouch.Multipart View Source

Module for handling multipart streams.

Used internally, but can be used in other applications.

Link to this section Summary

Functions

Reads the subtype and boundary from a multipart/* content type header, if found

Joins all given parts into one multipart stream

Joins a part to form a chunk of multipart stream data

Splits an entire multipart stream into its parts

Splits the incoming data up if a boundary was found. Also expects and extracts the header

Link to this section Functions

Link to this function get_boundary(headers) View Source
get_boundary(headers :: [{charlist, charlist} | {binary, binary}] | %{optional(String.t) => String.t}) ::
  {:ok, subtype :: String.t, boundary :: String.t} |
  nil

Reads the subtype and boundary from a multipart/* content type header, if found.

Link to this function join(parts, boundary) View Source
join(parts :: [{headers :: %{optional(String.t) => String.t} | [{String.t, String.t}], data :: binary} | binary], boundary :: binary) :: binary

Joins all given parts into one multipart stream.

Link to this function join_part(headers, data, boundary) View Source
join_part(headers :: %{optional(String.t) => String.t} | [{String.t | atom, String.t}] | nil, data :: binary | nil, boundary :: binary) :: binary

Joins a part to form a chunk of multipart stream data.

According to specification, each part ends with a line break after the data.

Link to this function split(data, boundary) View Source
split(data :: binary, boundary :: binary) ::
  {:ok, parts :: [{headers :: map, body :: binary}]} |
  :error

Splits an entire multipart stream into its parts.

Returns error if the stream is incomplete.

Link to this function split_part(data, boundary) View Source
split_part(data :: binary, boundary :: binary) :: {previous :: binary, next_headers :: map | nil, rest :: binary | nil}

Splits the incoming data up if a boundary was found. Also expects and extracts the header.

Return values:

  • previous - data which belongs to the previous part, ready to be used; can be empty
  • next_headers - if not nil, a new part has been found; can be an empty map
  • rest - data which might belong to the next part or is uncertain; nil when an end boundary has been found