Skip to content
Class · Format description concepts

TextForm: text-based file formats and how they differ from binary

Published Formatory editorial team

Text form is the representation of a format's content as a sequence of characters in a declared character encoding, readable without format-specific software.

Registries use it to separate character-based formats and serializations from binary ones, together with the encoding and line-ending conventions the text follows.

A file is “text” when its bytes, decoded in a known character encoding, give a sequence of characters that is the content. Nothing else is needed to read it: a text editor, a terminal or a printed hex dump with an encoding table will do. Formats with this property belong to the text form class, and the distinction from binary encoding turns out to be one of the most useful facts a registry can record about a format.

The obvious members are CSV, XML, HTML, JSON, YAML, Markdown and SVG, plus program source code in languages such as Fortran and C++. The less obvious ones are formats that look binary in reputation but have a text serialization: PostScript, RTF and the ASCII variants of several 3D and image formats.

Formats with two forms

Some specifications define both a text form and a binary form of the same model. The pattern is common in 3D graphics and simple imaging.

  • PLY states its form in the header: format ascii 1.0, format binary_little_endian 1.0 or format binary_big_endian 1.0.
  • STL has an ASCII variant beginning with solid and a binary variant with an 80-byte header followed by a triangle count. Some binary files also start with the word “solid” in that header, which fools naive identification.
  • Netpbm pairs each type: P1/P4 for bitmaps, P2/P5 for grayscale, P3/P6 for color, the first of each pair being text.

For a registry, these are either two related formats or one format with a text-form property, and the choice affects identification. The text variant is usually larger and slower to parse; the binary variant carries a byte order that the text variant does not have.

What a text form record needs

Calling a format “text” leaves three questions open.

Character encoding. US-ASCII, ISO-8859-1, Windows-1252, UTF-8 and UTF-16 all count as text, and a file’s bytes cannot always reveal which one applies. XML declares its encoding in the prolog, HTML in a meta element or HTTP header, while CSV usually declares nothing. Recording the expected or permitted encodings is the first step toward reading the file correctly later.

Line endings. LF, CR LF and CR are all in use. Most parsers tolerate the difference; fixed-width scientific data and some legacy mainframe formats do not.

Byte order mark. UTF-8 files sometimes start with EF BB BF. Some tools add it, others treat it as stray characters at the start of the first field, which is a classic cause of a mysterious column name in a CSV import.

Why identification is harder

Binary formats often start with a signature (%PDF-, PK, 89 50 4E 47). Text formats mostly do not. XML has its prolog, PostScript starts with %!, but a CSV, a Fortran file and a plain-text note can be byte-for-byte indistinguishable in their first hundred characters. Identification tools therefore fall back on extensions and content heuristics for text formats, and the file format identification guide describes how that evidence is weighed.

A historical hazard is worth a mention: FTP’s ASCII mode rewrote line endings in transit. Applied to a binary file by mistake, it corrupted every 0x0A or 0x0D byte, and old collections still contain archives and images damaged that way. Other format properties are listed in the vocabulary index.

Example in RDF

# the same triangle mesh header in two forms of the PLY format
ply                                ply
format ascii 1.0                   format binary_little_endian 1.0
element vertex 3                   element vertex 3
property float x                   property float x
...                                ...

<format rdf:about="https://example.org/formats/ply-ascii">
  <textForm>true</textForm>
  <characterEncoding>US-ASCII</characterEncoding>
</format>

Questions about TextForm

What is a text form of a file format?

It is a version of the format in which all content is written as characters, so the file opens in a plain text editor. CSV, XML, JSON, SVG and program source code are text formats; JPEG and ZIP are binary.

Can one format have both a text form and a binary form?

Yes. STL meshes come in ASCII and binary variants, PLY declares ascii or binary in its header, the Netpbm family has P3 (text) and P6 (binary) color images, and Autodesk FBX exists in both forms.

Why does the character encoding matter for text formats?

The same bytes decode to different characters in different encodings. Without knowing whether a file is UTF-8, Latin-1 or Windows-1252, accented letters and symbols may be read wrongly, and the damage is often invisible until someone reads the text.

What are the line ending conventions?

Unix and macOS use LF (0x0A), Windows uses CR LF (0x0D 0x0A), and classic Mac OS before OS X used CR (0x0D). Many formats accept any of them, but some, such as fixed-width data files, break when the wrong one is used.

Are text formats better for long-term preservation?

They are easier to inspect and recover by hand, which counts in their favor. They are not automatically safer: undeclared encodings, inconsistent line endings and loose syntax cause their own problems, and binary formats with open specifications preserve well too.

More from Format description concepts

All 16 in this group