What File Formats Does PI Desktop Export To? Complete MIME‑Type Mapping Guide

PI Desktop exports pasted clipboard data to CSV, HTML, JSON, PDF, ZIP, plain text, and standard image formats (PNG, JPG, WebP, AVIF, etc.) by mapping MIME types to extensions in the saveComposerPasteFiles function, with a fallback to .bin for unknown types.

PI Desktop is an open-source Electron application that transforms clipboard paste operations into persisted files. When users paste data into the composer interface, the application analyzes the MIME type and saves the content to disk using specific file extensions defined in the source code.

Supported Export Formats

Document and Data Files

The MIME_EXTENSIONS table in apps/desktop/electron/main/composer-paste.ts (lines 33‑44) defines the core export mappings:

  • text/csv → .csv
  • text/html → .html
  • text/plain → .txt
  • application/json → .json
  • application/pdf → .pdf
  • application/zip → .zip

Image Formats

For any MIME type starting with image/, PI Desktop validates the file against a whitelist of accepted extensions defined in lines 20‑31 of composer-paste.ts:

  • .avif, .bmp, .gif, .heic, .jpeg, .jpg, .png, .tif, .tiff, .webp

Unknown Type Fallback

When the MIME type is not recognized in the mapping table, the system defaults to the .bin extension. This ensures binary data is preserved without corruption or incorrect formatting.

How the Export Logic Works

The export process centers on the saveComposerPasteFiles function located in apps/desktop/electron/main/composer-paste.ts.

When paste data arrives as an array of ComposerPasteFile objects, the function normalizes each MIME type (converting to lowercase and trimming whitespace) or defaults to application/octet-stream. The fileNameOf helper (lines 75‑84) then appends the appropriate extension from MIME_EXTENSIONS or falls back to .bin if the type is absent from the map.

The file is written to a session‑specific scratch directory, and metadata including path, name, kind, mimeType, and size is returned to the renderer process for UI display.

Practical Code Examples

Exporting a CSV File

import { saveComposerPasteFiles } from "@pi-desktop/shared";

const csvPaste = {
  name: "report",
  mimeType: "text/csv",
  data: new Uint8Array(Buffer.from("a,b,c\n1,2,3")),
};

const exported = await saveComposerPasteFiles(
  "/Users/me/.pi-desktop/data",
  "session-123",
  [csvPaste]
);

console.log(exported[0].path); // -> .../session-123/pasted-<uuid>-report.csv

Saving a PDF Document

const pdfPaste = {
  name: "contract",
  mimeType: "application/pdf",
  data: pdfUint8Array,
};

const [file] = await saveComposerPasteFiles(
  "/home/user/.pi-desktop/data",
  "session-xyz",
  [pdfPaste]
);

console.log(file.extension); // ".pdf"

Handling Unknown MIME Types

const unknownPaste = {
  name: "mystery",
  mimeType: "application/x-custom",
  data: Uint8Array.from([0x00, 0x01, 0x02]),
};

const [file] = await saveComposerPasteFiles(
  "/tmp/pi-data",
  "sess-1",
  [unknownPaste]
);

console.log(file.name); // "mystery.bin"

Summary

  • PI Desktop supports CSV, HTML, TXT, JSON, PDF, and ZIP exports via explicit MIME‑to‑extension mappings in composer-paste.ts.
  • Image files are supported through a whitelist covering AVIF, BMP, GIF, HEIC, JPEG, PNG, TIFF, and WebP formats.
  • The export logic is implemented in apps/desktop/electron/main/composer-paste.ts within the saveComposerPasteFiles function.
  • Unknown MIME types gracefully fallback to the .bin extension to prevent data loss.
  • The system writes files to session‑specific scratch directories and returns complete metadata to the UI.

Frequently Asked Questions

What file formats does PI Desktop support for exporting pasted data?

PI Desktop supports CSV, HTML, plain text, JSON, PDF, and ZIP archives, plus standard image formats including PNG, JPEG, GIF, WebP, AVIF, BMP, HEIC, and TIFF. The complete mapping is defined in the MIME_EXTENSIONS table in apps/desktop/electron/main/composer-paste.ts at lines 33‑44.

How does PI Desktop handle image exports?

When the MIME type starts with image/, PI Desktop validates the file extension against a whitelist located at lines 20‑31 of composer-paste.ts. If the extension matches (e.g., .png, .jpg), the file is saved with that extension; otherwise, it falls back to .bin to ensure safe storage.

What happens if I paste a file with an unrecognized MIME type?

The system defaults to the .bin extension. This fallback protects data integrity by storing the raw bytes without attempting to parse or convert them to an inappropriate format, making it safe for custom or proprietary file types.

Where is the export logic located in the PI Desktop source code?

The core export logic resides in apps/desktop/electron/main/composer-paste.ts. This file contains the saveComposerPasteFiles function, the MIME_EXTENSIONS mapping table (lines 33‑44), and the image extension whitelist (lines 20‑31).

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →