Netstrings v1.1.0 Netstrings

netstring encoding and decoding

An implementation of djb’s netstrings.

Please note that the decoder violates spec by accepting leading zeros in the len part. However, the encoder will never generate such leading zeros.

Summary

Functions

Decode netstrings

Encode a netstring

Converts an io device into a Netstrings.Stream

Functions

decode(ns)

Specs

decode(String.t) ::
  {:ok, [String.t], String.t} |
  {:error, String.t}

Decode netstrings

The decoder will stop as soon as it encounters an improper or incomplete netstring. Upon success, decoded strings will appear in the second element of the tuple as a list. Any remaining (undecoded) part of the string will appear as the third element.

There are no guarantees that the remainder is the start of a proper netstring. Appending more received data to the remainder may or may not allow it to be decoded.

encode(str)

Specs

encode(String.t) :: {:ok | :error, String.t}

Encode a netstring

stream(device)

Specs

stream(atom | pid) :: Enumerable.t

Converts an io device into a Netstrings.Stream

Behaves similarly to an IO.Stream with the values marshaled into and out of netstring format. The device should be opened in raw format for predictability.

Please note that while this works, at present, it has very poor error handling and has many untested edges. Use with caution.