From 85b3211f8a22133458a9c9c83d1e7a2645a1f640 Mon Sep 17 00:00:00 2001 From: Adam Rice Date: Wed, 27 Nov 2019 18:10:13 -0800 Subject: [PATCH] Add the concept of a "compression context" (#19) Add a "compression context" to CompressionStream and DecompressionStream to make the tracking of the internal state explicit. --- index.bs | 14 ++++++++------ index.html | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/index.bs b/index.bs index c96d9d010..fe4deeca4 100644 --- a/index.bs +++ b/index.bs @@ -64,6 +64,8 @@ A chunk is a piece of data. In the case of CompressionStream and DecompressionSt A stream represents an ordered sequence of chunks. The terms {{ReadableStream}} and {{WritableStream}} are defined in [[!WHATWG-STREAMS]]. +A compression context is the internal state maintained by a compression or decompression algorithm. The contents of a compression context depend on the format, algorithm and implementation in use. From the point of view of this specification, it is an opaque object. A compression context is initially in a start state such that it anticipates the first byte of input. + # Supported formats # {#supported-formats} : `deflate` @@ -122,7 +124,7 @@ interface CompressionStream { CompressionStream includes GenericTransformStream; -A {{CompressionStream}} has an associated format. +A {{CompressionStream}} has an associated format and compression context context. The {{CompressionStream}}(*format*) constructor, when invoked, must run these steps: 1. If *format* is unsupported in CompressionStream, then throw a TypeError. @@ -137,7 +139,7 @@ The {{CompressionStream}}(*format*) constructor, when invoked, must run these st The compress and enqueue a chunk algorithm, given a CompressionStream object *cs* and a *chunk*, runs these steps: 1. If *chunk* is not a {{BufferSource}} type, then return a promise rejected with a TypeError. - 1. Let *buffer* be the result of compressing *chunk* with *cs*'s format. + 1. Let *buffer* be the result of compressing *chunk* with *cs*'s format and context. 1. Let *controller* be *cs*'s transform.\[[TransformStreamController]]. 1. If *buffer* is empty, return a promise resolved with undefined. 1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays. @@ -146,7 +148,7 @@ The compress and enqueue a chunk algorithm, given a CompressionStream The compress flush and enqueue algorithm, which handles the end of data from the input ReadableStream object, given a CompressionStream object *cs*, runs these steps: - 1. Let *buffer* be the result of compressing an empty input with *cs*'s format, with the finish flag. + 1. Let *buffer* be the result of compressing an empty input with *cs*'s format and context, with the finish flag. 1. If *buffer* is empty, return a promise resolved with undefined. 1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays. 1. For each Uint8Array *array*, call TransformStreamDefaultControllerEnqueue(*controller*, *array*). @@ -163,7 +165,7 @@ interface DecompressionStream { DecompressionStream includes GenericTransformStream; -A {{DecompressionStream}} has an associated format. +A {{DecompressionStream}} has an associated format and compression context context. The {{DecompressionStream}}(*format*) constructor, when invoked, must run these steps: 1. If *format* is unsupported in DecompressionStream, then throw a TypeError. @@ -178,7 +180,7 @@ The {{DecompressionStream}}(*format*) constructor, when invoked, must run these The decompress and enqueue a chunk algorithm, given a DecompressionStream object *ds* and a *chunk*, runs these steps: 1. If *chunk* is not a {{BufferSource}} type, then return a promise rejected with a TypeError. - 1. Let *buffer* be the result of decompressing *chunk* with *ds*'s format. If this results in an error, then return a promise rejected with a TypeError. + 1. Let *buffer* be the result of decompressing *chunk* with *ds*'s format and context. If this results in an error, then return a promise rejected with a TypeError. 1. Let *controller* be *ds*'s transform.\[[TransformStreamController]]. 1. If *buffer* is empty, return a promise resolved with undefined. 1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays. @@ -187,7 +189,7 @@ The decompress and enqueue a chunk algorithm, given a DecompressionSt The decompress flush and enqueue algorithm, which handles the end of data from the input ReadableStream object, given a DecompressionStream object *ds*, runs these steps: - 1. Let *buffer* be the result of decompressing an empty input with *ds*'s format, with the finish flag. + 1. Let *buffer* be the result of decompressing an empty input with *ds*'s format and context, with the finish flag. 1. If the end of the compressed input has not been reached, return a promise rejected with a TypeError. 1. If *buffer* is empty, return a promise resolved with undefined. 1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays. diff --git a/index.html b/index.html index e8afad448..96e63906d 100644 --- a/index.html +++ b/index.html @@ -1215,7 +1215,7 @@ - +