ZIM File Example

From openZIM
Jump to navigation Jump to search

Example of a small zim file

This is a example of a small zim file. You can find the documentation about the format at ZIM File Format.

0000000: 5a49 4d04 0500 0000 19fd 9100 732b cfb6  ZIM.........s+..
0000010: 3406 5519 ac2e 03c4 0300 0000 0100 0000  4.U.............
0000020: 6600 0000 0000 0000 7e00 0000 0000 0000  f.......~.......
0000030: ce00 0000 0000 0000 5000 0000 0000 0000  ........P.......
0000040: ffff ffff ffff ffff 2701 0000 0000 0000  ........'.......
0000050: 7465 7874 2f68 746d 6c00 7465 7874 2f70  text/html.text/p
0000060: 6c61 696e 0000 8a00 0000 0000 0000 a000  lain............
0000070: 0000 0000 0000 b800 0000 0000 0000 0000  ................
0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..
0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto..
00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto
00000b0: 6d6f 6269 6c65 0000 0100 0042 0000 0000  mobile.....B....
00000c0: 0000 0000 0100 0000 4175 746f 0000 d600  ........Auto....
00000d0: 0000 0000 0000 04fd 377a 585a 0000 0169  ........7zXZ...i
00000e0: 22de 3602 0021 0110 0000 00a8 708e 86e0  ".6..!......p...
00000f0: 001c 0018 5e00 0600 34fb de91 72a3 8034  ....^...4...r..4
0000100: fc31 871f e6aa 6104 7025 b184 dc00 00e1  .1....a.p%......
0000110: 66f9 e700 0130 1d01 efc6 9c90 4299 0d01  f....0......B...
0000120: 0000 0000 0159 5a6c d75d be78 953c 79d9  .....YZl.].x.<y.
0000130: 5054 034b 5726 c4                        PT.KW&....

Header

0000000: 5a49 4d04 0500 0000 19fd 9100 732b cfb6  ZIM.........s+..

This is the magic number 72173914, which is in hex 44D495A and since all data is little endian, the result is this 5a49 4d04.

0000000: 5a49 4d04 0500 0000 19fd 9100 732b cfb6  ZIM.........s+..

The major version number of the zim format is 5...

0000000: 5a49 4d04 0500 0000 19fd 9100 732b cfb6  ZIM.........s+..

...and the minor version number is 0.

0000000: 5a49 4d04 0500 0000 19fd 9100 732b cfb6  ZIM.........s+..
0000010: 3406 5519 ac2e 03c4 0300 0000 0100 0000  4.U.............

The uuid.

0000010: 3406 5519 ac2e 03c4 0300 0000 0100 0000  4.U.............

The file has 3 articles.

0000010: 3406 5519 ac2e 03c4 0300 0000 0100 0000  4.U.............

And one cluster.

0000020: 6600 0000 0000 0000 7e00 0000 0000 0000  f.......v.......

You will find the url pointer list at offset 0000 0000 0000 0066.

0000020: 6600 0000 0000 0000 7e00 0000 0000 0000  f.......v.......

The title pointer list follows at offset 0000 0000 0000 007e.

0000030: ce00 0000 0000 0000 5000 0000 0000 0000  ........P.......

The cluster pointer list can be found at offset 0000 0000 0000 00ce.

0000030: ce00 0000 0000 0000 5000 0000 0000 0000  ........P.......

A list of used mime types is at offset 0000 0000 0000 0050.

0000040: ffff ffff ffff ffff 2701 0000 0000 0000  ........'.......

No main page is defined here...

0000040: ffff ffff ffff ffff 2701 0000 0000 0000  ................

...nor a layout page.

0000040: ffff ffff ffff ffff 2701 0000 0000 0000  ................

A md5 checksum of the file until that can be found at 0000 0000 0000 0127.

Mime type list

0000050: 7465 7874 2f68 746d 6c00 7465 7874 2f70  text/html.text/p
0000060: 6c61 696e 0000 8a00 0000 0000 0000 a000  lain............

As seen the mime type list starts at 0000 0000 0000 0050.

0000050: 7465 7874 2f68 746d 6c00 7465 7874 2f70  text/html.text/p
0000060: 6c61 696e 0000 8a00 0000 0000 0000 a000  lain..~.........

Mime types are zero terminated.

0000050: 7465 7874 2f68 746d 6c00 7465 7874 2f70  text/html.text/p
0000060: 6c61 696e 0000 8a00 0000 0000 0000 a000  lain..~.........

After the last mime type, a single zero byte follows.

Url pointer list

0000060: 6c61 696e 0000 8a00 0000 0000 0000 a000  lain............
0000070: 0000 0000 0000 b800 0000 0000 0000 0000  ................

The url pointer list starting at 0000 0000 0000 0066 has 3 pointers to the 3 directory entries of the 3 articles. The list is ordered by the url of the articles. The first directory entry can be found at 0000 0000 0000 008a, the second at 0000 0000 0000 00a0 and the third at 0000 0000 0000 00b8.

Title pointer list

0000070: 0000 0000 0000 b800 0000 0000 0000 0000  ................
0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..

Here is the title pointer list.

0000070: 0000 0000 0000 b800 0000 0000 0000 0000  ................
0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..

When ordering by title, the article number 0 is the first. This actually refers to the 0th article in the url pointer list. To find the directory entry of the article, you have to look up the offset in the url pointer list. The offset to the directory entry can be found at (url-pointer-list + 0*sizeof(pointer))=0066+0*8=0066.

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A.. 

When ordering by title, the article number 1 is the second. The offset to the directory entry can be found at (url-pointer-list + 1*sizeof(pointer))=0066+1*8=006E.

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A.. 

When ordering by title, the article number 2 is the third. The offset to the directory entry can be found at (url-pointer-list + 2*sizeof(pointer))=0066+2*8=0076.

Directory entry

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..
0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto..

This is the first directory entry at 008a.

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..

The article has the 0th mime type from the list, which is "text/html".

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..

No extra bytes are set.

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..

The namespace of the article is 'A'.

0000080: 0000 0100 0000 0200 0000 0000 0041 0000  .............A..
0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto..

The version is 0000 0000.

0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto..

The data can be found in cluster 0.

0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto.. 

And it is the 0th blob in the cluster.

0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto..

The url of the article is "Auto" and is zero terminated.

0000090: 0000 0000 0000 0000 0000 4175 746f 0000  ..........Auto.. 

The title is empty and hence the title is the same as the url: "Auto".

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto
00000b0: 6d6f 6269 6c65 0000 0100 0042 0000 0000  mobile.....B....

The second directory entry can be found at offset 0000 0000 0000 00a0 and is the Article "Automobile" of namespace 'A'.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto

The mime type is set to ffff, which means, that this is a redirect.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto 

No extra bytes are set.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto 

The namespace of the redirect is 'A'.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto 

The version is 0000 0000.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto 

It points to the 0th article, which is A/Auto.

00000a0: ffff 0041 0000 0000 0000 0000 4175 746f  ...A........Auto
00000b0: 6d6f 6269 6c65 0000 0100 0042 0000 0000  mobile.....B....

The url of the redirect is "Automobile" and is zero terminated.

00000b0: 6d6f 6269 6c65 0000 0100 0042 0000 0000  mobile.....B....
00000c0: 0000 0000 0100 0000 4175 746f 0000 d600  ........Auto....
00000d0: 0000 0000 0000 04fd 377a 585a 0000 0169  ........7zXZ...i

The next directory entry can be found at offset 0000 0000 0000 00b8 and is the Article "Auto" of namespace 'B'.

00000b0: 6d6f 6269 6c65 0000 0100 0042 0000 0000  mobile.....B....

The mimetype is entry number 1 and hence the 2nd since the first is the number 0. The mimetype is then "text/plain". The rest of the directory entry is similar to the first one.

Cluster pointer list

00000c0: 0000 0000 0100 0000 4175 746f 0000 d600  ........Auto....
00000d0: 0000 0000 0000 04fd 377a 585a 0000 0169  ........7zXZ...i

The cluster pointer list is just one offset in this case. The cluster can be found at offset 0000 0000 0000 00d6.

Cluster

00000d0: 0000 0000 0000 04fd 377a 585a 0000 0169  ........7zXZ...i
00000e0: 22de 3602 0021 0110 0000 00a8 708e 86e0  ".6..!......p...
00000f0: 001c 0018 5e00 0600 34fb de91 72a3 8034  ....^...4...r..4
0000100: fc31 871f e6aa 6104 7025 b184 dc00 00e1  .1....a.p%......
0000110: 66f9 e700 0130 1d01 efc6 9c90 4299 0d01  f....0......B...
0000120: 0000 0000 0159 5a6c d75d be78 953c 79d9  .....YZl.].x.<y.

This is the cluster. Note that you can't know how large the cluster is until you uncompress the first bytes.

00000d0: 0000 0000 0000 04fd 377a 585a 0000 0169  ........7zXZ...i

The first byte specifies the compression algorithm, which is 4, which means lzma (or more precise xz) here.

uncompressed cluster

When uncompressing the data we get

0000000: 0c00 0000 1900 0000 1d00 0000 3c68 313e  ............<h1>
0000010: 4175 746f 3c2f 6831 3e41 7574 6f         Auto</h1>Auto
0000000: 0c00 0000 1900 0000 1d00 0000 3c68 313e  ............<h1>

The offset to the first blob in the uncompressed data is 0000 000c. There are 3 offsets in the cluster since 0c are 3*4 byte offsets. 2 offsets to the start and the last is always a offset to the end of the cluster.

0000000: 0c00 0000 1900 0000 1d00 0000 3c68 313e  ............<h1>

The offset to the second blob in the uncompressed data is 0000 0019. This is also the end of the first blob.

0000000: 0c00 0000 1900 0000 1d00 0000 3c68 313e  ............<h1>

The cluster has 0000 001d bytes uncompressed data and the end of the second (last) blob.

0000000: 0c00 0000 1900 0000 1d00 0000 3c68 313e  ............<h1>
0000010: 4175 746f 3c2f 6831 3e41 7574 6f         Auto</h1>Auto

This is the data of the first blob from offset 00c0 to 0019-1.

0000010: 4175 746f 3c2f 6831 3e41 7574 6f         Auto</h1>Auto

This is the data of the first blob from offset 0019 to 001d-1.

See also