Files and contents

A file in a template can carry its contents with it, so the folder you deploy arrives with the boilerplate already written. How that works depends on the kind of file: Prefab keeps text as text, and everything else as a copy of the original.

Text files and everything else

Text files - Markdown, source code, configuration, plain text - are stored in the template as text. You edit them inside Prefab, and placeholders written inside them are filled in on deploy.

Everything else - images, .psd, .docx, PDFs, audio, archives - is copied into Prefab's own storage and written out byte for byte. Prefab offers no editor for these, because there is nothing useful it could show you.

Prefab decides which is which from the file's extension, and the inspector says which it settled on: Editable File or Binary File.

Placeholders are not filled in inside binary files

Rewriting bytes in the middle of a .psd or a .docx would corrupt it, so Prefab copies these files untouched. A placeholder in the file name still works - only the contents are left alone.

Writing a file's starting contents

Select a text file and its panel offers two views. Info summarises what the file is, where it came from and what it will contain. Content is the editor: type the file's starting contents, with a line and character count along the bottom and a Variables button listing the four built-in placeholders. Save keeps the changes, and moving away with unsaved text asks before discarding anything.

Files Prefab cannot edit show the Info panel alone. So does a text file that has had a real file attached to it, because the attached copy is what deploys.

The Info panel for a file, showing its category, contents, source location and an Update from Source button
The Info panel for a file, showing its category, contents, source location and an Update from Source button
The Contents row is the one to check: it says what this entry will actually deploy.

What the Contents row tells you

Every file's Info panel has a Contents row, and it is worth reading before you deploy. It says one of four things:

  • A size, such as 2.4 MB - a copy of a real file is attached, and those bytes are what get written
  • Copied file - a copy is attached, but its size could not be read
  • A character count, such as 184 characters - the text in the Content view is what gets written
  • Empty file - nothing is attached and no text is written, so the file deploys at zero bytes

An empty entry is rarely what anyone wanted: a Logo.psd that deploys as a zero-byte file is a broken deliverable. Attach File… points the entry at a real file; on an entry that already has one, the same button reads Replace File….

Keeping a file in step with its original

A file that came from disk - imported with a folder, or added with Import Files… - remembers where it came from. The Info panel shows it under From, with the full path underneath, and clicking the name reveals the original in FinderFile Explorer.

Templates outlive the files in them. The letterhead gets revised, the session file gains a track, and Update from Source re-reads the original so the template can catch up without being rebuilt. The button reports what happened:

  • Updated from … - the original had changed, and the template now holds the new version
  • Already up to date - the original is identical to what the template holds
  • Couldn't read … - it may have moved or been deleted - the original could not be reached
  • This file has no original to re-read - the entry was created inside Prefab

To do the whole template at once, use Update Files from Source in the ⋯ menu beside Create…. It checks every file that remembers an origin, then reports how many it checked, how many it updated, and how many it could not read.

When the original moves or disappears

Prefab tracks the original through a bookmark rather than a path, and a bookmark follows a file that has been moved or renamed. Drag the original into a different folder and Update from Source still finds it, and the recorded path updates itself to wherever it now is.

What a remembered location cannot survive is the file being deleted, or the template travelling to a machine where that file never existed. The panel then labels the row Imported from and gives its value as Not reachable from this MacPC, with the remembered path below so you can see which file it was looking for.

The template still deploys. The copy Prefab stored is used, exactly as before; only the ability to re-read a fresh version is gone.

Files created inside Prefab have no origin at all. There is nothing to re-read, because Prefab is where they are edited.

How Prefab stores the copies

Non-text files are kept in a store shared with Prefab's other components, identified by a hash of their contents. Two consequences are worth knowing:

  • The same file used in two templates, or a template duplicated, is stored once
  • An unchanged file re-read from source resolves to the copy already held, which is how Already up to date is answered without comparing anything

Copies that nothing refers to any more are cleared out after templates load and after a template is deleted.

A single file can be up to 100 MB

Importing a folder that holds something larger brings the file in as an empty entry and names it under the import's warnings. Pointing at one with Attach File… does nothing at all: the Contents row still says Empty file afterwards, which is the only sign that it was refused.

Exporting a template as a .prefab file carries those copies with it, so the files deploy on the receiving machine too. See Sharing templates.