gildas-lormeau / Polyglot-HTML-ZIP-PNG

Learn how to create HTML/ZIP/PNG polyglot files in JavaScript
https://gildas-lormeau.github.io/Polyglot-HTML-ZIP-PNG/
MIT License
25 stars 4 forks source link
html javascript pdf png polyglot-files self-extracting-zip single-file zip

HTML Meets ZIP Meets PNG: When Files Have More Layers Than an Onion

Introduction

Imagine a digital chameleon: a file that combines ZIP, HTML, and PNG into one versatile format. It can be displayed as a web page, unzipped to obtain all the page's resources, or viewed as an image. Discover an innovative approach to sharing and storing web content, and learn how to create these polyglot files in JavaScript!

Presentation

You can view the web presentation in:

Press F1 during the presentation to see the keyboard shortcuts.

TL;DR

Here is the resulting self-extracting HTML file: demo.png.zip.html

This file and the presentation files are compatible with:

If you are intrigued or more curious, you can also view it on HexEd.it.

The presentation explains how to generate this file and the technical challenges involved.

Fun fact: the image displayed at the center of the page demo.png.zip.html is the page itself, but interpreted as a PNG file (cf. the <img src="https://github.com/gildas-lormeau/Polyglot-HTML-ZIP-PNG/raw/main/#" ...> tag).

Viewing the presentation in Chromium (and WebKit) browsers

If you are using a Chromium-based or a WebKit-based browser to run the first examples from the presentation, you should install the extension from the zip file located in util/web-extension in order to add the support of file:// URIs in the Fetch API. Alternatively, you can view the examples via an HTTP server. This issue is addressed in the subsequent examples of the presentation.

Creation of polyglot files with single-file

Install single-file-cli from NPM and run single-file as shown below.

npm install single-file-cli
npx single-file \
  --compress-content \
  --self-extracting-archive \
  --embedded-image=./image.png \
  --dump-content \
  https://www.example.com > output.png.zip.html

Known Issues

Thank You

This presentation is dedicated to my biggest supporter on this project. Many thanks @ljonathanl, we miss your enthusiasm and creativity.