IOData
A protocol for efficently working with data (like binaries and iolists) with minimal copying.
Implementations are provided for
- binaries
- iolists
- files & file descriptors
- slices of other iodata
Usage
Splitting a binary or iolist at a given index:
iex> IOData.split!("hello world", 5)
{"hello", " world"}
iex> IOData.split!(["h", "ello", [[" "], "world"]], 5)
{["h", "ello"], [[[" "], "world"]]}Slicing out a section of a binary or iolist:
iex> IOData.to_iodata!("hello world", 4, 5)
"o wor"
iex> IOData.to_iodata!(["h", "ello", [[" "], "world"]], 4, 5)
["o", " ", "wor"]Slicing out a section of a binary or iolist while converting it to a binary:
iex> IOData.to_binary!("hello world", 4, 5)
"o wor"
iex> IOData.to_binary!(["h", "ello", [[" "], "world"]], 4, 5)
"o wor"Determining whether an IOData has at least n bytes (without counting them all):
iex> IOData.at_least?("hello world", 4)
true
iex> IOData.at_least?(["h", "ello", [[" "], "world"]], 4)
true