Code Monkey home page Code Monkey logo

mathiasbynens / small Goto Github PK

View Code? Open in Web Editor NEW
1.9K 36.0 186.0 82 KB

Smallest possible syntactically valid files of different types

Home Page: https://mathiasbynens.be/notes/minimal-html

Makefile 0.16% Ada 2.15% C++ 0.96% C# 2.39% Eiffel 0.48% Fortran 0.96% Haskell 1.84% HTML 70.79% Inform 7 2.95% Java 2.63% Pascal 0.88% C 0.80% Go 2.08% Batchfile 0.08% COBOL 7.98% Scala 0.64% DIGITAL Command Language 0.08% Assembly 0.64% Mercury 0.96% Rich Text Format 0.56%

small's Introduction

Smallest possible […] file

This repository aims to collect the smallest possible syntactically valid files in different programming/scripting/markup languages.

It all started with a blog post on the smallest possible HTML/XHTML files

Pull requests welcome!

Mathias

License

To the extent possible under law, the author has waived all copyright and related or neighboring rights to this work.

File types

Archives

Audio

Documents

Executables

Graphics

Languages

Markup

Video

Unsorted

small's People

Contributors

alokmenghrajani avatar alrra avatar angea avatar aqua-ye avatar bcarl avatar davidak avatar dhaigh avatar dmak avatar dscorbett avatar edwellbrook avatar gweax avatar jvhellemond avatar kalifg avatar kanaka avatar kud avatar mathiasbynens avatar mems avatar mgeier avatar mre avatar rbirkby avatar rgbkrk avatar richtr avatar rmm5t avatar sdkrup avatar shritesh avatar sigvef avatar smt923 avatar tetyys avatar timmywil avatar zegnat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

small's Issues

Request: png

I see the smallest transparent png. But is that necessarily the smallest png?

Problems with C file.

Empty string is the smallest valid c code - it has no executable code and no data, but it remains valid. You can compile it to an object file (.o) and a shared library (.so on UNIX). So the c file in this repo should be an empty file, as this is exactly the smallest valid file of this type.
What you can't do with it, is to link it as a program, as that requires exactly one main function. That is what you're aiming for in the current c file. But there are a few problems with this file (int main;):

  • As mentioned above, this is not the smallest possible c file.
  • The file produces undefined behavior. Normally, main is a function. You've declared main as an int variable. In such case, the C standard AFAIK doesn't specify what happens, although it's permitted (i.e. it's undefined behavior). What a c compiler will typically do in this case, is to put the contents of main in an executable section and call it. This actually allows to run any machine code by assigning an array to main. Anyway, in this case, calling main causes the computer to run machine code consisting of one or more zero bytes (depending on the size of int), which e.g. on my linux x86-64 system causes a segmentation fault. To fix this, you can make main an empty function, by adding {} (returning 0 from main is implicit).
  • The type (int) is not needed, int is an implicit type used in c when none is given. Also, the ending semicolon is not needed as well.
    Given the above, I propose the following:
  • Make c.c an empty file.
  • Add another file, maybe called c_program.c, with the following contents: main(){}.

html5.html is invalid

<!DOCTYPE html> isn't valid HTML5 courtesy of https://html5.validator.nu/

At a minimum, the title element is required, and it must have a value:

<!DOCTYPE html><title>_</title>

is the smallest valid HTML5 document that I'm aware of.

WebP

Smallest possible WebP image.

Seen it done with gif. Would be cool to see how small WebP could be.

TIFF is not valid

TIFF added in #86 is not entirely valid, and both libtiff and ImageMagick complain about it.

$ tiffinfo tiff.tif
TIFFReadDirectory: Warning, TIFF directory is missing required "StripByteCounts" field, calculating from imagelength.
$ magick identify tiff.tif
identify: TIFF directory is missing required "StripByteCounts" field, calculating from imagelength. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/956.
identify: improper image header `tiff.tif' @ error/tiff.c/ReadTIFFImage/1349.

As I read the standard, it should add the StripByteCounts field, and terminate the IFD with a zero long to indicate no more IFDs.

mp3 format is not correct

➜  Desktop ffprobe -i mp3.mp3
ffprobe version 4.0.1 Copyright (c) 2007-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[mp3 @ 0x7fb4d7002a00] Format mp3 detected only with low score of 1, misdetection possible!
[mp3 @ 0x7fb4d7002a00] Invalid frame size (72): Could not seek to 72.
mp3.mp3: Invalid argument

MP3 file no longer work - here's a new one

The one from #57 doesn't work anymore (DEMUXER_ERROR_COULD_NOT_OPEN: FFmpegDemuxer: open context failed in browser and Invalid frame size (72): Could not seek to 72 in ffmpeg).

Here's a new one with 76 bytes: mp3.zip

data:audio/mpeg;base64,/+MYwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYwA==

HTML5 file has syntax errors

The current content of the HTML5 (<!DOCTYPE html>) has syntax errors:

syntax error

This means that there must be present a <title> element in the document, being this the final code:

<!DOCTYPE html><title>x</title>

The same validates properly:

validated

This was verified using https://html5.validator.nu/

java

an empty .java is compilable by javac, or even class A{} in A.java is compilable.

Smaller versions?

C - main; - who cares about result? It's syntactically valid...
zip - data:application/zip;base64,UEsFBgAAAAAAAAAAAAAAAAAA - 18 bytes

AVIF

AV1 Image File Format (AVIF).

A 307 byte version: AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABkAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgSAAAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACFtZGF0EgAKBzgADtAgIGkyDB/wYAALAAAAhPPLwA==

But there are probably way smaller sizes possible.

XMP

The smallest possible XMP (metadata file) is

<x:xmpmeta xmlns:x="adobe:ns:meta/"/>

(validated with xmp validator)

license?

It would be helpful if this repository had a license! I realize for some of the files (like the python example...) this is a ridiculous thing to request, but for the others, it would be nice to know what the terms of re-use are. Otherwise it's hard to know if/how I can use these files in my own projects.

Add diff

i thought what the smallest possible (git) diff would be

the answer would fit greatly in this repo

c.c is invalid

Exporting an int as 'main' is not a legal C program. This will crash with a bus error on OS X, SEGV on Debian 8 and FreeBSD 10.

Minimal PDF

Not the smallest, but based on Adobe PDF specification "minimal PDF file" (aka "Hello World" PDF): Minimal PDF

JPEG XL

@jonsneyers (who worked on the spec) has been tweeting small JPEG XL artworks recently. If anyone knows what the smallest possible valid JPEG XL document looks like, it's probably him. :)

Don't include empty files

Wouldn't it be better to include a list in the README of formats/languages for which the minimal file is an empty file?

[Requesting comment] Smallest possible XML file

By strict reading of the XML 1.0 standard am I right to assume the smallest possible XML file is the following?

<?xml version='1.0'?><_/>

This does validate as ‘well-formed XML’ on the W3C Markup Validator. The only odd part is that the root element is seen as _/ rather than _. Looks like a bug, because it does treat the slash as a closing slash.

Not sure if I should pull, requesting comment.


A XML document is:

document      ::=   prolog element Misc*

Where:

prolog        ::=   XMLDecl? Misc* (doctypedecl Misc*)?
XMLDecl       ::=   '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
VersionInfo   ::=   S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
Eq            ::=   S? '=' S?
VersionNum    ::=   '1.' [0-9]+

And:

element       ::=   EmptyElemTag
                    | STag content ETag

With:

EmptyElemTag  ::=   '<' Name (S Attribute)* S? '/>'

While:

Name          ::=   NameStartChar (NameChar)*

In short we get this when all optional (marked by ? or *) parts are left out:

document      ::= '<?xml' S 'version' '=' ("'" '1.' [0-9]+ "'" | '"' '1.' [0-9]+ '"') '?>' '<' NameStartChar '/>'

C code is implementation dependent

According to the C99 standard:

The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:

int main(void) { /\* ... \*/ }

or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):

int main(int argc, char \*argv[]) { /\* ... \*/ }

or equivalent;10) or in some other implementation-defined manner.

Also, it requires a new line at the end:

A nonempty source file does not end in a new-line character which is not immediately
preceded by a backslash character or ends in a partial preprocessing token or
comment (5.1.1.2).

(Section J.2 Undefined behaviour)

So if you want something that should work in all implementations that conform to the standard, the file c.c has to be (return 0; is implied at the end, as per 5.1.2.2.3).

int main(void){}

(With a newline at the end, 17 bytes in total)

jpeg is not usable

Firefox, IE, and Windows Photo Viewer all claim that the 125-byte JPEG image is corrupt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.