Module binary

An implementation of a subset of the Erlang/OTP binary interface.

Function Index

at/2 Get a byte from a binary by index.
copy/1 Returns a copy of the binary.
copy/2 Returns a binary containing N copies of the input binary.
decode_hex/1 Decodes a hex encoded binary into a binary.
encode_hex/1 Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits "a" to "f".
encode_hex/2 Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits "a" to "f".
list_to_bin/1 Works exactly as erlang:list_to_binary/1.
longest_common_prefix/1 Returns the length of the longest common prefix of the binaries in the list.
match/2Find the first occurrence of Pattern in Binary.
match/3Find the first occurrence of Pattern in Binary.
part/3Get the part of a given binary.
replace/3 Replaces first occurrence of Pattern in Binary with Replacement.
replace/4 Replaces occurrences of Pattern in Binary with Replacement.
split/2Split a binary according to pattern.
split/3Split a binary according to pattern.

Function Details

at/2


at(Binary::binary(), Index::non_neg_integer()) -> byte()

Binary: binary to get a byte from
Index: 0-based index of the byte to return

returns: value of the byte from the binary

Get a byte from a binary by index.

copy/1


copy(Binary::binary()) -> binary()

Binary: binary to copy

returns: a copy of the binary

Returns a copy of the binary.

copy/2


copy(Binary::binary(), N::non_neg_integer()) -> binary()

Binary: binary to copy
N: number of times to copy the binary

returns: a binary containing N copies of the input binary

Returns a binary containing N copies of the input binary.

decode_hex/1


decode_hex(Data::<<_:_*16>>) -> binary()

Data: hex encoded binary to decode

returns: decoded binary

Decodes a hex encoded binary into a binary.

encode_hex/1


encode_hex(Data::binary()) -> binary()

Data: binary data to convert into hex encoded binary

returns: hex encoded binary

Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits “a” to “f”.

encode_hex/2


encode_hex(Data::binary(), Case::lowercase | uppercase) -> binary()

Data: binary data to convert into hex encoded binary
Case: which case to encode into

returns: hex encoded binary

Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits “a” to “f”.

list_to_bin/1


list_to_bin(ByteList::iolist()) -> binary()

ByteList: iolist to convert to binary

returns: binary representation of ByteList

Works exactly as erlang:list_to_binary/1. This function is provided for completeness.

longest_common_prefix/1


longest_common_prefix(Binaries::[binary(), ...]) -> non_neg_integer()

Binaries: non-empty list of binaries

returns: length of the longest common prefix of all binaries in the list

Returns the length of the longest common prefix of the binaries in the list.

match/2


match(Binary::binary(), Pattern::binary() | [binary()]) -> {non_neg_integer(), non_neg_integer()} | nomatch

Binary: binary to search in
Pattern: pattern to search for

returns: {Start, Length} or nomatch

Equivalent to match(Binary, Pattern, []).

Find the first occurrence of Pattern in Binary.

match/3


match(Binary::binary(), Pattern::binary() | [binary()], Options::[term()]) -> {non_neg_integer(), non_neg_integer()} | nomatch

Binary: binary to search in
Pattern: pattern to search for
Options: options for the match

returns: {Start, Length} or nomatch

Find the first occurrence of Pattern in Binary. Options can include {scope, {Start, Length}}.

part/3


part(Binary::binary(), Pos::non_neg_integer(), Len::integer()) -> binary()

Binary: binary to extract a subbinary from
Pos: 0-based index of the subbinary to extract
Len: length, in bytes, of the subbinary to extract.

returns: a subbinary from Binary

Get the part of a given binary. A negative length can be passed to count bytes backwards.

replace/3


replace(Binary::binary(), Pattern::binary(), Replacement::binary()) -> binary()

Binary: binary where the replacements should occur
Pattern: binary pattern which is to be replaced
Replacement: binary which will replace the pattern

returns: resulting binary after replacements

Equivalent to replace(Binary, Pattern, Replacement, []).

Replaces first occurrence of Pattern in Binary with Replacement. If Pattern is not found, returns the original binary unchanged. Pattern and Replacement must be binaries.

replace/4


replace(Binary::binary(), Pattern::binary(), Replacement::binary(), Options::[global] | []) -> binary()

Binary: binary where the replacements should occur
Pattern: binary pattern which is to be replaced
Replacement: binary which will replace the pattern
Options: list of options for the replacement operations.

returns: resulting binary after replacements

Replaces occurrences of Pattern in Binary with Replacement. If Options includes global, replaces all occurrences; otherwise, replaces just the first occurrence. If Pattern is not found, returns the original binary unchanged. Pattern and Replacement must be binaries. Only implemented option is global.

split/2


split(Binary::binary(), Pattern::binary()) -> [binary()]

Binary: binary to split
Pattern: pattern to perform the split

returns: a list composed of one or two binaries

Equivalent to split(Binary, Pattern, []).

Split a binary according to pattern. If pattern is not found, returns a singleton list with the passed binary. Unlike Erlang/OTP, pattern must be a binary.

split/3


split(Binary::binary(), Pattern::binary(), Option::[global]) -> [binary()]

Binary: binary to split
Pattern: pattern to perform the split

returns: a list composed of one or two binaries

Split a binary according to pattern. If pattern is not found, returns a singleton list with the passed binary. Unlike Erlang/OTP, pattern must be a binary. Only implemented option is global