Skip to content

Commit

Permalink
Introduce "deflate-raw" algorithm (cloudflare#43)
Browse files Browse the repository at this point in the history
Add the "deflate-raw" algorithm for DEFLATE with no header or footer.
  • Loading branch information
yutakahirano authored Mar 31, 2022
1 parent 805fc62 commit 6d344f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
8 changes: 7 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ urlPrefix: http://www.ecma-international.org/ecma-262/6.0/index.html; spec: ECMA

*This section is non-normative.*

The APIs specified in this specification are used to compress and decompress streams of data. They support "deflate" and "gzip" as compression algorithms. They are widely used by web developers.
The APIs specified in this specification are used to compress and decompress streams of data. They support "deflate", "deflate-raw" and "gzip" as compression algorithms. They are widely used by web developers.

# Conformance # {#conformance}

Expand Down Expand Up @@ -79,6 +79,12 @@ A <dfn>compression context</dfn> is the internal state maintained by a compressi
* It is an error for DecompressionStream if the `ADLER32` checksum is not correct.
* It is an error if there is additional input data after the `ADLER32` checksum.

: `deflate-raw`
:: "The DEFLATE algorithm" [[!RFC1951]]

* Implementations must be "compliant" as described in [[!RFC1951]] section 1.4.
* Non-[[!RFC1951]]-conforming blocks must not be created by CompressionStream, and are errors for DecompressionStream.

: `gzip`
:: "GZIP file format" [[!RFC1952]]

Expand Down
28 changes: 19 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
<title>Compression Streams</title>
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<link href="https://www.w3.org/StyleSheets/TR/2021/cg-draft" rel="stylesheet">
<meta content="Bikeshed version 15125077e, updated Fri Jan 14 14:49:38 2022 -0800" name="generator">
<meta content="Bikeshed version fb1e763a4, updated Tue Mar 1 13:13:50 2022 -0800" name="generator">
<link href="https://wicg.github.io/compression/" rel="canonical">
<meta content="03341243b006ef0244f4c687b60eccdb37329e5c" name="document-revision">
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
Expand Down Expand Up @@ -633,7 +632,7 @@
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2021/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">Compression Streams</h1>
<p id="w3c-state"><a href="https://www.w3.org/standards/types#CG-DRAFT">Draft Community Group Report</a>, <time class="dt-updated" datetime="2022-01-18">18 January 2022</time></p>
<p id="w3c-state"><a href="https://www.w3.org/standards/types#CG-DRAFT">Draft Community Group Report</a>, <time class="dt-updated" datetime="2022-03-28">28 March 2022</time></p>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
Expand Down Expand Up @@ -704,7 +703,7 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<h2 class="heading settled" data-level="1" id="introduction"><span class="secno">1. </span><span class="content">Introduction</span><a class="self-link" href="#introduction"></a></h2>
<p><em>This section is non-normative.</em></p>
<p>The APIs specified in this specification are used to compress and decompress streams of data. They support "deflate" and "gzip" as compression algorithms. They are widely used by web developers.</p>
<p>The APIs specified in this specification are used to compress and decompress streams of data. They support "deflate", "deflate-raw" and "gzip" as compression algorithms. They are widely used by web developers.</p>
<h2 class="heading settled" data-level="2" id="conformance"><span class="secno">2. </span><span class="content">Conformance</span><a class="self-link" href="#conformance"></a></h2>
<p>As well as sections marked as non-normative, all authoring guidelines,
diagrams, examples, and notes in this specification are non-normative.
Expand Down Expand Up @@ -746,6 +745,15 @@ <h2 class="heading settled" data-level="4" id="supported-formats"><span class="s
<li data-md>
<p>It is an error if there is additional input data after the <code>ADLER32</code> checksum.</p>
</ul>
<dt data-md><code>deflate-raw</code>
<dd data-md>
<p>"The DEFLATE algorithm" <a data-link-type="biblio" href="#biblio-rfc1951">[RFC1951]</a></p>
<ul>
<li data-md>
<p>Implementations must be "compliant" as described in <a data-link-type="biblio" href="#biblio-rfc1951">[RFC1951]</a> section 1.4.</p>
<li data-md>
<p>Non-<a data-link-type="biblio" href="#biblio-rfc1951">[RFC1951]</a>-conforming blocks must not be created by CompressionStream, and are errors for DecompressionStream.</p>
</ul>
<dt data-md><code>gzip</code>
<dd data-md>
<p>"GZIP file format" <a data-link-type="biblio" href="#biblio-rfc1952">[RFC1952]</a></p>
Expand Down Expand Up @@ -942,11 +950,11 @@ <h2 class="heading settled" data-level="7" id="privacy-security"><span class="se
<h2 class="heading settled" data-level="8" id="examples"><span class="secno">8. </span><span class="content">Examples</span><a class="self-link" href="#examples"></a></h2>
<h3 class="heading settled" data-level="8.1" id="example-gzip-compress-stream"><span class="secno">8.1. </span><span class="content">Gzip-compress a stream</span><a class="self-link" href="#example-gzip-compress-stream"></a></h3>
<pre class="example highlight" id="example-470647ba"><a class="self-link" href="#example-470647ba"></a><c- a>const</c-> compressedReadableStream
<c- o>=</c-> inputReadableStream<c- p>.</c->pipeThrough<c- p>(</c-><c- k>new</c-> CompressionStream<c- p>(</c-><c- t>'gzip'</c-><c- p>));</c->
<c- o>=</c-> inputReadableStream<c- p>.</c->pipeThrough<c- p>(</c-><c- ow>new</c-> CompressionStream<c- p>(</c-><c- t>'gzip'</c-><c- p>));</c->
</pre>
<h3 class="heading settled" data-level="8.2" id="example-deflate-compress"><span class="secno">8.2. </span><span class="content">Deflate-compress an ArrayBuffer to a Uint8Array</span><a class="self-link" href="#example-deflate-compress"></a></h3>
<pre class="example highlight" id="example-09e4ae49"><a class="self-link" href="#example-09e4ae49"></a><c- k>async</c-> <c- a>function</c-> compressArrayBuffer<c- p>(</c->input<c- p>)</c-> <c- p>{</c->
<c- a>const</c-> cs <c- o>=</c-> <c- k>new</c-> CompressionStream<c- p>(</c-><c- t>'deflate'</c-><c- p>);</c->
<c- a>const</c-> cs <c- o>=</c-> <c- ow>new</c-> CompressionStream<c- p>(</c-><c- t>'deflate'</c-><c- p>);</c->
<c- a>const</c-> writer <c- o>=</c-> cs<c- p>.</c->writable<c- p>.</c->getWriter<c- p>();</c->
writer<c- p>.</c->write<c- p>(</c->input<c- p>);</c->
writer<c- p>.</c->close<c- p>();</c->
Expand All @@ -960,7 +968,7 @@ <h3 class="heading settled" data-level="8.2" id="example-deflate-compress"><span
output<c- p>.</c->push<c- p>(</c->value<c- p>);</c->
totalSize <c- o>+=</c-> value<c- p>.</c->byteLength<c- p>;</c->
<c- p>}</c->
<c- a>const</c-> concatenated <c- o>=</c-> <c- k>new</c-> Uint8Array<c- p>(</c->totalSize<c- p>);</c->
<c- a>const</c-> concatenated <c- o>=</c-> <c- ow>new</c-> Uint8Array<c- p>(</c->totalSize<c- p>);</c->
<c- a>let</c-> offset <c- o>=</c-> <c- mf>0</c-><c- p>;</c->
<c- k>for</c-> <c- p>(</c-><c- a>const</c-> array <c- k>of</c-> output<c- p>)</c-> <c- p>{</c->
concatenated<c- p>.</c->set<c- p>(</c->array<c- p>,</c-> offset<c- p>);</c->
Expand All @@ -971,9 +979,9 @@ <h3 class="heading settled" data-level="8.2" id="example-deflate-compress"><span
</pre>
<h3 class="heading settled" data-level="8.3" id="example-gzip-decompress"><span class="secno">8.3. </span><span class="content">Gzip-decompress a Blob to Blob</span><a class="self-link" href="#example-gzip-decompress"></a></h3>
<pre class="example highlight" id="example-4d353c2c"><a class="self-link" href="#example-4d353c2c"></a><c- a>function</c-> decompressBlob<c- p>(</c->blob<c- p>)</c-> <c- p>{</c->
<c- a>const</c-> ds <c- o>=</c-> <c- k>new</c-> DecompressionStream<c- p>(</c-><c- t>'gzip'</c-><c- p>);</c->
<c- a>const</c-> ds <c- o>=</c-> <c- ow>new</c-> DecompressionStream<c- p>(</c-><c- t>'gzip'</c-><c- p>);</c->
<c- a>const</c-> decompressionStream <c- o>=</c-> blob<c- p>.</c->stream<c- p>().</c->pipeThrough<c- p>(</c->ds<c- p>);</c->
<c- k>return</c-> <c- k>new</c-> Response<c- p>(</c->decompressedStream<c- p>).</c->blob<c- p>();</c->
<c- k>return</c-> <c- ow>new</c-> Response<c- p>(</c->decompressedStream<c- p>).</c->blob<c- p>();</c->
<c- p>}</c->
</pre>
<h2 class="heading settled" data-level="9" id="acknowledgments"><span class="secno">9. </span><span class="content">Acknowledgments</span><a class="self-link" href="#acknowledgments"></a></h2>
Expand Down Expand Up @@ -1148,6 +1156,8 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
<dl>
<dt id="biblio-rfc1950">[RFC1950]
<dd>P. Deutsch; J-L. Gailly. <a href="https://www.rfc-editor.org/rfc/rfc1950"><cite>ZLIB Compressed Data Format Specification version 3.3</cite></a>. May 1996. Informational. URL: <a href="https://www.rfc-editor.org/rfc/rfc1950">https://www.rfc-editor.org/rfc/rfc1950</a>
<dt id="biblio-rfc1951">[RFC1951]
<dd>P. Deutsch. <a href="https://www.rfc-editor.org/rfc/rfc1951"><cite>DEFLATE Compressed Data Format Specification version 1.3</cite></a>. May 1996. Informational. URL: <a href="https://www.rfc-editor.org/rfc/rfc1951">https://www.rfc-editor.org/rfc/rfc1951</a>
<dt id="biblio-rfc1952">[RFC1952]
<dd>P. Deutsch. <a href="https://www.rfc-editor.org/rfc/rfc1952"><cite>GZIP file format specification version 4.3</cite></a>. May 1996. Informational. URL: <a href="https://www.rfc-editor.org/rfc/rfc1952">https://www.rfc-editor.org/rfc/rfc1952</a>
<dt id="biblio-rfc2119">[RFC2119]
Expand Down

0 comments on commit 6d344f7

Please sign in to comment.