# `wand.compat` — Compatibility layer

This module provides several encoding-related utilities.

wand.compat.binary(string, var=None)

  Makes `string` to `bytes`.

  Parameters:

    - string (`bytes`, `str`, `unicode`) – a string to cast it to `bytes`

    - var (`str`) – an optional variable name to be used for error message

wand.compat.encode_filename(filename)

  If `filename` is a `text_type`, encode it to `bytes` according to filesystem’s default encoding.

  Changed in version 0.5.3: Added support for PEP-519 https://github.com/emcconville/wand/pull/339

wand.compat.to_bytes(value, string_pattern='{0}')

  Short-cut method to allow mixed value types to be converted to bytes.

  Parameters:

    - value (`basestring`, `int`, `float`) – Value to be cast to bytes

    - string_pattern (`basestring`) – String format to allow printf style control of bytes output.

  Added in version 0.6.4.