Working with files › What is inside a file · 8 min read

Text or binary

Underneath, every file is the same thing: zeros and ones. What changes is what those zeros and ones represent.

In a text file, each little group of bits represents a character: a letter, a number, a space, a line break. And because everyone agreed decades ago on which number belongs to which letter, any program can read it without knowing anything about the other.

TEXT — .md .csv .html .svg

Change line 3. The other six stay untouched.

BINARY — .pdf .docx .png

%PDF-1.7 %âãÏÓ 4 0 obj
<</Filter/FlateDecode/Le
ngth 3721>> stream xœÝ]
Ë’ãÆ‘Ýç+ ¦’&†½Ø€ û¢‡
$Á>zÐ ‰Ì4ÅêGwSj4? ~
ïÌ*€Á éÑ ˆD&3+ó Uåÿ
|üåo ¿þòË/¿ üðà ×_
¿ýío ï~÷Ý ï¾ûî endst

There is no "line 3". The whole file is regenerated.

The difference is what you can point at.

In a binary file the bits mean something else: the color of a pixel, the length of a compressed block, which byte page 4 starts at. Only the program that wrote it knows what each one means.

No letters, no lines. Just a block.

The kitchen test: open it with Notepad. If you can read it, it is text. If you see a mess of symbols, those are bits that are not letters, and Notepad is showing them to you as if they were.

Why can you edit a single line of a text file but not of a PDF?

snack 1 of 6 · From bits to letters

This snack lives in What is inside a file · Working with files

Powered by KlugerByte