What is MIME type "text/x-peg"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

text/x-peg designates files that contain Parsing Expression Grammars.
These files define rules for breaking down and understanding text. They guide software on how to interpret patterns and syntax.
Files with this MIME type are usually saved with the PEG extension.
This MIME type tells software that the fileโ€™s content is not just plain text, but contains specific rules to analyze and convert text accurately.
For further details, see the Parsing Expression Grammar on Wikipedia.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-peg    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-peg">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-peg');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

What is a .peg file used for?

A file with the .peg extension contains a Parsing Expression Grammar, which is a set of rules describing how to interpret specific text patterns. These files are typically used by developers to generate parsers for programming languages or data formats. You can find more details about the extension at PEG.

How do I open a file with the text/x-peg MIME type?

Since text/x-peg files are essentially plain text, you can view and edit them using any standard text editor like Notepad, Sublime Text, or Visual Studio Code. Specialized code editors may offer syntax highlighting to make reading the grammar rules easier.

How do I configure Apache to serve .peg files correctly?

To ensure your Apache server sends the correct MIME type, add the following line to your .htaccess file or main configuration: AddType text/x-peg .peg. This tells the server to identify files with the .peg extension as Parsing Expression Grammars.

Why does the MIME type start with 'x-'?

The x- prefix in text/x-peg indicates that it is a non-standard or experimental type that has not been formally registered with the IANA. It is a convention used to define private file types before they become standardized.

Can web browsers execute text/x-peg files?

No, web browsers cannot execute or run PEG files. If you navigate to one in a browser, it will likely display the raw text content or prompt you to download the file, as browsers do not have built-in engines to process parsing grammars.

Is text/x-peg safe to open?

Yes, files with the text/x-peg MIME type are non-executable text files, making them generally safe to open and read. However, they are designed to be input for parser generators, so a malformed file could potentially cause issues (like infinite loops) within the software designed to process it.

What should I do if my server serves .peg files as text/plain?

Serving them as text/plain is functionally acceptable since the content is human-readable, but it loses the semantic meaning of the file. To fix this, update your web server's MIME type configuration to explicitly associate the .peg extension with text/x-peg.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.