Version

January 10, 2023 ยท View on GitHub

  • Version: 0.5.0
  • Date: 2023-Jan-06

License

This specification document is (C) 2022-2023 Even Rouault and licensed under the CC-BY-4.0 terms.

Note: the scope of the copyrighted material does, of course, not extend onto any source or binary code derived from the specification.

Introduction

This document specifies a third-party extra field, to be able to encode arbitrary key-value pairs of text metadata associated with a file within a ZIP. For example, this could be used to store the Content-Type of a file, along with an attribution or source statement.

Specification

The encoding MUST follow the requirements of "4.6 Third Party Mappings" of the ZIP specification

In the following, uint16 is a 16-bit unsigned integer, encoded in little-endian order (least significant byte first), and byte a 8-bit unsigned integer.

OffsetTypeNameComment
0uint16header_idConstant 0x564B (bytes 'K' 'V')
2uint16payload_sizeNumber of bytes following this field.
4byte[]signatureConstant "KeyValuePairs" (13 bytes)
17bytekv_countNumber of key-value pairs.
18uint16kv1_key_sizeSize in bytes of the first key.
20byte[]kv1_key_textUTF-8 encoded value of the first key.
uint16kv1_val_sizeSize in bytes of the first value.
byte[]kv1_val_textUTF-8 encoded value of the first value.
.......
uint16kvN_key_sizeSize in bytes of the last key.
byte[]kvN_key_textUTF-8 encoded value of the last key.
uint16kvN_val_sizeSize in bytes of the last value.
byte[]kvN_val_textUTF-8 encoded value of the last value.

Example

Encoding of a ("Content-Type", "text/plain") key-value pair:

OffsetBytesComment
04B 56header_id
228 00payload_size (40 bytes)
44B 65 79 56 61 6C 75 65 50 61 69 72 73signature ("KeyValuePairs")
1701kv_count
180C 00kv1_key_size (12 bytes)
2043 6F 6E 74 65 6E 74 2D 54 79 70 65kv1_key_text ("Content-Type")
320A 00kv1_val_size (10 bytes)
3474 65 78 74 2F 70 6C 61 69 6Ekv1_val_text ("text/plain")

Total: 44 bytes

Annex A: Software implementations

GDAL (C/C++ library)

The sozip development branch of GDAL contains an implementation of this specification.