binhex.rst 1.68 KB
Newer Older
1 2 3 4 5 6 7 8
:mod:`binhex` --- Encode and decode binhex4 files
=================================================

.. module:: binhex
   :synopsis: Encode and decode files in binhex4 format.


This module encodes and decodes files in binhex4 format, a format allowing
9
representation of Macintosh files in ASCII. Only the data fork is handled.
10 11 12 13 14 15 16 17 18 19 20

The :mod:`binhex` module defines the following functions:


.. function:: binhex(input, output)

   Convert a binary file with filename *input* to binhex file *output*. The
   *output* parameter can either be a filename or a file-like object (any object
   supporting a :meth:`write` and :meth:`close` method).


21
.. function:: hexbin(input, output)
22 23 24

   Decode a binhex file *input*. *input* may be a filename or a file-like object
   supporting :meth:`read` and :meth:`close` methods. The resulting file is written
25
   to a file named *output*, unless the argument is ``None`` in which case the
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
   output filename is read from the binhex file.

The following exception is also defined:


.. exception:: Error

   Exception raised when something can't be encoded using the binhex format (for
   example, a filename is too long to fit in the filename field), or when input is
   not properly encoded binhex data.


.. seealso::

   Module :mod:`binascii`
      Support module containing ASCII-to-binary and binary-to-ASCII conversions.


.. _binhex-notes:

Notes
-----

There is an alternative, more powerful interface to the coder and decoder, see
the source for details.

If you code or decode textfiles on non-Macintosh platforms they will still use
53
the old Macintosh newline convention (carriage-return as end of line).
54 55 56

As of this writing, :func:`hexbin` appears to not work in all cases.