<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="lib/rfc2629.xslt"?>
<?rfc toc="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes"?>
<?rfc subcompact="no" ?>
<?rfc linkmailto="no" ?>
<?rfc editing="no" ?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc rfcedstyle="yes"?>
<?rfc-ext allow-markup-in-artwork="yes" ?>
<?rfc-ext include-index="no" ?>

<rfc ipr="trust200902"
     category="exp"
     docName="draft-thierry-bulk-barf-00"
     xmlns:x="http://purl.org/net/xml2rfc/ext">
  <x:feedback template="mailto:pierre@nothos.net"/>
  <front>
    <title abbrev="BULK-BARF">BULK ARchive Format</title>

    <author initials="P." surname="Thierry" fullname="Pierre Thierry">
      <organization>Thierry Technologies</organization>
      <address>
        <email>pierre@nothos.net</email>
      </address>
    </author>

    <date day="7" month="August" year="2013" />
    <keyword>binary</keyword>

    <abstract>
      <t>
        This specification describes a BULK format to pack together independent pieces of data and
        metadata about them.
      </t>
    </abstract>

  </front>

  <middle>
    <section anchor="intro" title="Introduction">
      <section title="Rationale">
	<t>
	  There are plenty of archives formats currently in use, from widely-used and repurposed
	  formats like ZIP (used for generic file archives as well as Java deployment, ebooks and
	  office documents) to legacy formats like ARC or Z through moderately used formats enjoying
	  a stable niche, like tar, RAR or StuffIt.
	</t>
	<t>
	  A few archive formats actually make reuse of existing ones. Many archive formats
	  developped nowadays actually reuse ZIP without modification and just dictate the tree
	  structure inside the ZIP file. The Unix world has long had a tradition of separation of
	  concern, thus using different formats for archiving (ar or tar) and compression (gzip,
	  bzip2, lzma or now xz), with compressed archives named after the combination (foo.ar.gz,
	  bar.tar.bz2, etc.). Debian packages are actually ar files containing little uncompressed
	  metadata and a couple of compressed tar files.
	</t>
	<t>
	  But the problem remains that all these binary formats all define completely ad hoc
	  syntaxes, sometimes incredibly optimized but narrowly tailored to their specific
	  requirements. Many leave little room for future extension, or in a contrived way (many
	  formats are actually extended by abusing an unused metadata field and cramming a new ad
	  hoc format in it).
	</t>
	<t>
	  Some of these formats have a few fixed- or limited-length fields that became or will
	  become obsolete in time. The ar format, for example, suffers from the Year 2038 problem
	  and cannot store long file names. Various implementations have used different incompatible
	  extensions to store long file names.
	</t>
	<t>
	  So we propose yet another archive format, that uses an efficient but extensible syntax, so
	  that the format cannot fail to be extended or modified for new use cases or constraints.
	</t>
      </section>

      <section title="Format overview">
	<t>
	  A BARF file is basically a set of metadata fields followed by data entries. Each entry
	  consists of a set of metadata fields followed by its content. The interesting property of
	  using BULK is that any portion of that structure is dynamic (no fixed metadata fields, and
	  an entry without metadata is serialized as its content, as with BULK, the entry and its
	  content cannot be confused with each other) and anything can be enclosed in a BULK
	  structure to add features.
	</t>
	<t>
	  Metadata fields are just a BULK expression, which means that any ad hoc or standard BULK
	  vocabulary can be used in an efficient way as metadata. Mutually incompatible metadata
	  vocabularies could even be stored alongside each other for legacy support, if need be.
	</t>
	<t>
	  The archive file can be compressed or encrypted by an outside tool (producing a
	  foo.barf.gz or bar.pgp file, for example), but so can any individual BULK expression. The
	  entire archive, internally to the file, can be a BULK compression or encryption form, as
	  well as any metadata set, metadata field or entry. Almost any extension and optimization
	  can be retrofitted in this structure in a backward-compatible way, like checksums, digital
	  signature or access offsets for random access.
	</t>
	<t>
	  This extends the use case of BARF archives outside of archives for multiple files. An
	  extensible image format could be based on a BARF structure, allowing seamless transition
	  from a simple format to a full-featured one, whereas existing formats usually add complex
	  extensions that fail to be widely adopted (to add support for layers, transparency,
	  different compression or metadata). Although BARF would probably be ill-suited for
	  playable audio and video, it would still provide a perfect fit for the storage of raw
	  audio and video for editing programs.
	</t>
      </section>

      <section title="Conventions and Terminology">
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD
          NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as
          described in <xref target="RFC2119">RFC 2119</xref>.
        </t>
        <t>
          Literal numerical values are provided in decimal or hexadecimal as appropriate.
          Hexadecimal literals are prefixed with <spanx style="verb">0x</spanx> to distinguish them
          from decimal literals.
        </t>
	<t>
	  BULK bytes sequences and expressions are described with the same conventions than used in
	  the <xref target="BULK1">BULK 1.0 specification</xref>
	</t>
      </section>
    </section>

    <section title="Guaranteed Backward Compatibility">
      <t>
	This specification defines the notion of Guaranteed Backward Compatibility (GBC). It applies
	to forms that carry a main payload with additional metadata. A form that obeys the rules of
	GBC has the type GBCForm.
      </t>
      <t>
	A GBCForm has the shape <spanx style="verb">( Ref {arguments} {next}:Expr )</spanx>. If the
	payload of a GBCForm is readable without knowledge of that form, then {next} MUST be that
	payload. Otherwise, {next} MUST be nil.
      </t>
      <t>
	For example, a GBC-compliant checksum form could have the shape <spanx style="verb">( crc32c
	{crc}:Word32 {payload} )</spanx>, where {crc} is the checksum of the byte sequence
	{payload}. On the other hand, a GBC-compliant encryption form, where obviously the payload
	is unreadable without proper knowledge of the form, could have the shape <spanx
	style="verb">( encrypt {payload} nil )</spanx>.
      </t>
    </section>

    <section title="BULK archive namespace">
      <t>
	The archive namespace (mnemonic: <spanx style="verb">barf</spanx>) is an official namespace
	identified by the UUID <eref target="urn:uuid:8beba7c6-c65d-5256-a2da-3763513953f3"/> (BULK,
	"Stack 'em. Pack 'em. And rack 'em."). It provides a standard way to pack one or more data
	elements together with metadata.
      </t>

      <section title="Packing">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x1</spanx> (mnemonic: <spanx
	    style="verb">pack</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( pack {metadata}:Expr {entries} )</spanx></t>
	  </list>
	</t>
	<t>
	  This packs archive entries together as a form. {metadata} holds metadata about the whole
	  pack. In the context of {metadata}, <spanx style="verb">rdf:this-resource</spanx>
	  designates the whole pack.
	</t>
      </section>

      <section title="Stacking">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x2</spanx> (mnemonic: <spanx
	    style="verb">stack</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( stack {metadata}:Expr {entries-metadata} ) {entries}</spanx></t>
	  </list>
	</t>
	<t>
	  This stacks archive entries together as a sequence, for the cases where it is not
	  appropriate for entries to belong to a single expression. {metadata} holds metadata about
	  the whole stack. In the context of {metadata}, <spanx
	  style="verb">rdf:this-resource</spanx> designates the whole stack. {entries-metadata} MUST
	  be a sequence of expressions of length equal or inferior to the number of expressions in
	  {entries}. Each expression in {entries-metadata} holds metadata about a single entry of
	  the stack. In the context of such a metadata expression, <spanx
	  style="verb">rdf:this-resource</spanx> designates the described stack entry. By default,
	  the expression number N in {entries-metadata} describes the expression number N in
	  {entries}.
	</t>
	<t>
	  When the stack form is in the abstract yield, this has the property that if the last entry
	  is an Array, the actual payload constitutes the end of the BULK stream. This can make it
	  possible for BULK-unaware programs to read and/or write that payload easily.
	</t>
	<t>
	  Stacking also makes the addition of a metadata-carrying entry or a metadata-less entry an
	  append-only operation.
	</t>
      </section>

      <section title="Payload with metadata">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x3</spanx> (mnemonic: <spanx
	    style="verb">describe</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( describe {metadata} {payload}:Expr )</spanx></t>
	  </list>
	</t>
	<t>
	  This form associates arbitrary metadata with an arbitrary payload. It is intended to
	  constitute most entries in BARF archives. In the context of {metadata}, <spanx
	  style="verb">rdf:this-resource</spanx> designates the payload.
	</t>
	<t>Type: <spanx style="verb">GBCForm</spanx></t>
      </section>

      <section title="BULK stream embedding">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x4</spanx> (mnemonic: <spanx
	    style="verb">bulk-stream</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( bulk-streamm {payload} )</spanx></t>
	  </list>
	</t>
	<t>
	  This form makes it possible to include a complete BULK stream without modification, as
	  {payload}.
	</t>
	<t>Type: <spanx style="verb">GBCForm</spanx></t>
      </section>

      <section title="Compressed data">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x5</spanx> (mnemonic: <spanx
	    style="verb">compressed</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( compressed {method}:Expr {payload}:Array nil )</spanx></t>
	  </list>
	</t>
	<t>
	  This form encapsulates a compressed payload. This specification doesn't define names to
	  express a compression method.
	</t>
	<t>Type: <spanx style="verb">GBCForm</spanx></t>
      </section>

      <section title="Encrypted data">
	<t>
	  <list style="hanging">
	    <t hangText="name"><spanx style="verb">0x6</spanx> (mnemonic: <spanx
	    style="verb">encrypted</spanx> )</t>
	    <t hangText="shape"><spanx style="verb">( encrypted {method}:Expr {payload}:Array nil )</spanx></t>
	  </list>
	</t>
	<t>
	  This form encapsulates an encrypted payload. This specification doesn't define names to
	  express an encryption method.
	</t>
	<t>Type: <spanx style="verb">GBCForm</spanx></t>
      </section>

    </section>

    <section title="Security Considerations" anchor="sec">
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <reference anchor="RFC2119">
        <front>
          <title>
            Key words for use in RFCs to Indicate Requirement Levels
          </title>
          <author initials="S." surname="Bradner" fullname="Scott Bradner">
            <organization>Harvard University</organization>
            <address><email>sob@harvard.edu</email></address>
          </author>
          <date month="March" year="1997"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
      </reference>

      <reference anchor="BULK1">
	<front>
	  <title>Binary Uniform Language Kit 1.0</title>
	  <date day="7" month="August" year="2013"/>
	  <author initials="P." surname="Thierry" fullname="Pierre Thierry">
	    <organization>Thierry Technologies</organization>
	    <address>
	      <email>pierre@nothos.net</email>
	    </address>
	  </author>
	</front>
	<seriesInfo name="Internet-Draft" value="draft-thierry-bulk-02"/>
      </reference>

    </references>


    <references title="Informative references">
      <reference anchor="ISO8601">
	<front>
	  <title>ISO 8601:2004 Data elements and interchange formats -- Information interchange -- Representation
	  of dates and times</title>
	  <date year="2004"/>
	</front>
      </reference>
    </references>

  </back>
</rfc>

