Skip to content

Commit 1f0b64b

Browse files
authored
Use new Streams algorithms (#35)
Follows whatwg/streams#1073. Also includes minor editorial touchups to the algorithms as I was editing them. Also improves the Makefile.
1 parent d3b7150 commit 1f0b64b

File tree

3 files changed

+311
-361
lines changed

3 files changed

+311
-361
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
SHELL=/bin/bash
2+
13
index.html: index.bs
2-
curl https://api.csswg.org/bikeshed/ -F [email protected] -F force=1 > index.html
4+
@ (HTTP_STATUS=$$(curl https://api.csswg.org/bikeshed/ \
5+
--output index.html \
6+
--write-out "%{http_code}" \
7+
--header "Accept: text/plain, text/html" \
8+
-F die-on=warning \
9+
10+
[[ "$$HTTP_STATUS" -eq "200" ]]) || ( \
11+
echo ""; cat index.html; echo ""; \
12+
rm -f index.html; \
13+
exit 22 \
14+
);

index.bs

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@ A <dfn>compression context</dfn> is the internal state maintained by a compressi
9292
* A `gzip` stream may only contain one "member".
9393
* It is an error if there is additional input data after the end of the "member".
9494

95-
# Interface Mixin `GenericTransformStream` # {#generic-transform-stream}
96-
97-
The {{GenericTransformStream}} interface mixin represents the concept of a transform stream in IDL. It is not a TransformStream, though it has the same interface and it delegates to one.
98-
99-
<pre class="idl">
100-
interface mixin GenericTransformStream {
101-
readonly attribute ReadableStream readable;
102-
readonly attribute WritableStream writable;
103-
};
104-
</pre>
105-
106-
An object that includes {{GenericTransformStream}} has an associated <dfn>transform</dfn> of type TransformStream.
107-
108-
## Attributes ## {#outgoing-stream-attributes}
109-
110-
: <dfn attribute for="GenericTransformStream">readable</dfn>
111-
:: The `readable` attribute's getter, when invoked, must return this object's transform \[[readable]].
112-
: <dfn attribute for="GenericTransformStream">writable</dfn>
113-
:: The `writable` attribute's getter, when invoked, must return this object's transform \[[writable]].
114-
11595
# Interface `CompressionStream` # {#compression-stream}
11696

11797
<pre class="idl">
@@ -124,33 +104,26 @@ CompressionStream includes GenericTransformStream;
124104

125105
A {{CompressionStream}} has an associated <dfn for=CompressionStream>format</dfn> and <a>compression context</a> <dfn for=CompressionStream>context</dfn>.
126106

127-
The {{CompressionStream}}(*format*) constructor, when invoked, must run these steps:
128-
1. If *format* is unsupported in CompressionStream, then throw a TypeError.
129-
1. Let *cs* be a new CompressionStream object.
130-
1. Set *cs*'s <a for=CompressionStream>format</a> to *format*.
131-
1. Let *startAlgorithm* be an algorithm that takes no arguments and returns nothing.
132-
1. Let *transformAlgorithm* be an algorithm which takes a *chunk* argument and runs the <a>compress and enqueue a chunk</a> algorithm with *cs* and *chunk*.
133-
1. Let *flushAlgorithm* be an algorithm which takes no argument and runs the <a>compress flush and enqueue</a> algorithm with *cs*.
134-
1. Let *transform* be the result of calling <a abstract-op>CreateTransformStream</a>(*startAlgorithm*, *transformAlgorithm*, *flushAlgorithm*).
135-
1. Set *cs*'s <a>transform</a> to *transform*.
136-
1. Return *cs*.
137-
138-
The <dfn>compress and enqueue a chunk</dfn> algorithm, given a CompressionStream object *cs* and a *chunk*, runs these steps:
139-
1. If *chunk* is not a {{BufferSource}} type, then return <a>a promise rejected with</a> a TypeError.
107+
The <dfn constructor for=CompressionStream lt="CompressionStream(format)"><code>new CompressionStream(|format|)</code></dfn> steps are:
108+
1. If *format* is unsupported in {{CompressionStream}}, then throw a {{TypeError}}.
109+
1. Set [=this=]'s <a for=CompressionStream>format</a> to *format*.
110+
1. Let *transformAlgorithm* be an algorithm which takes a *chunk* argument and runs the <a>compress and enqueue a chunk</a> algorithm with [=this=] and *chunk*.
111+
1. Let *flushAlgorithm* be an algorithm which takes no argument and runs the <a>compress flush and enqueue</a> algorithm with [=this=].
112+
1. Set [=this=]'s [=GenericTransformStream/transform=] to the result of [=TransformStream/creating=] a {{TransformStream}} with <a for=TransformStream/create><var ignore>transformAlgorithm</var></a> set to *transformAlgorithm* and <a for=TransformStream/create><var ignore>flushAlgorithm</var></a> set to *flushAlgorithm*.
113+
114+
The <dfn>compress and enqueue a chunk</dfn> algorithm, given a {{CompressionStream}} object *cs* and a *chunk*, runs these steps:
115+
1. If *chunk* is not a {{BufferSource}} type, then throw a {{TypeError}}.
140116
1. Let *buffer* be the result of compressing *chunk* with *cs*'s <a for=CompressionStream>format</a> and <a for=CompressionStream>context</a>.
141-
1. Let *controller* be *cs*'s transform.\[[TransformStreamController]].
142-
1. If *buffer* is empty, return <a>a promise resolved with</a> undefined.
143-
1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays.
144-
1. For each Uint8Array *array*, call <a abstract-op>TransformStreamDefaultControllerEnqueue</a>(*controller*, *array*).
145-
1. Return <a>a promise resolved with</a> undefined.
117+
1. If *buffer* is empty, return.
118+
1. Split *buffer* into one or more non-empty pieces and convert them into {{Uint8Array}}s.
119+
1. For each {{Uint8Array}} *array*, [=TransformStream/enqueue=] *array* in *cs*'s [=GenericTransformStream/transform=].
146120

147-
The <dfn>compress flush and enqueue</dfn> algorithm, which handles the end of data from the input ReadableStream object, given a CompressionStream object *cs*, runs these steps:
121+
The <dfn>compress flush and enqueue</dfn> algorithm, which handles the end of data from the input {{ReadableStream}} object, given a {{CompressionStream}} object *cs*, runs these steps:
148122

149123
1. Let *buffer* be the result of compressing an empty input with *cs*'s <a for=CompressionStream>format</a> and <a for=CompressionStream>context</a>, with the finish flag.
150-
1. If *buffer* is empty, return <a>a promise resolved with</a> undefined.
151-
1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays.
152-
1. For each Uint8Array *array*, call <a abstract-op>TransformStreamDefaultControllerEnqueue</a>(*controller*, *array*).
153-
1. Return <a>a promise resolved with</a> undefined.
124+
1. If *buffer* is empty, return.
125+
1. Split *buffer* into one or more non-empty pieces and convert them into {{Uint8Array}}s.
126+
1. For each {{Uint8Array}} *array*, [=TransformStream/enqueue=] *array* in *cs*'s [=GenericTransformStream/transform=].
154127

155128

156129
# Interface `DecompressionStream` # {#decompression-stream}
@@ -165,34 +138,27 @@ DecompressionStream includes GenericTransformStream;
165138

166139
A {{DecompressionStream}} has an associated <dfn for=DecompressionStream>format</dfn> and <a>compression context</a> <dfn for=DecompressionStream>context</dfn>.
167140

168-
The {{DecompressionStream}}(*format*) constructor, when invoked, must run these steps:
169-
1. If *format* is unsupported in DecompressionStream, then throw a TypeError.
170-
1. Let *ds* be a new DecompressionStream object.
171-
1. Set *ds*'s <a for=DecompressionStream>format</a> to *format*.
172-
1. Let *startAlgorithm* be an algorithm that takes no arguments and returns nothing.
141+
The <dfn constructor for=DecompressionStream lt="DecompressionStream(format)"><code>new DecompressionStream(|format|)</code></dfn> steps are:
142+
1. If *format* is unsupported in {{DecompressionStream}}, then throw a {{TypeError}}.
143+
1. Set [=this=]'s <a for=DecompressionStream>format</a> to *format*.
173144
1. Let *transformAlgorithm* be an algorithm which takes a *chunk* argument and runs the <a>decompress and enqueue a chunk</a> algorithm with *ds* and *chunk*.
174145
1. Let *flushAlgorithm* be an algorithm which takes no argument and runs the <a>decompress flush and enqueue</a> algorithm with *ds*.
175-
1. Let *transform* be the result of calling <a abstract-op>CreateTransformStream</a>(*startAlgorithm*, *transformAlgorithm*, *flushAlgorithm*).
176-
1. Set *ds*'s <a>transform</a> to *transform*.
177-
1. Return *ds*.
146+
1. Set [=this=]'s [=GenericTransformStream/transform=] to the result of [=TransformStream/creating=] a {{TransformStream}} with <a for=TransformStream/create><var ignore>transformAlgorithm</var></a> set to *transformAlgorithm* and <a for=TransformStream/create><var ignore>flushAlgorithm</var></a> set to *flushAlgorithm*.
178147

179-
The <dfn>decompress and enqueue a chunk</dfn> algorithm, given a DecompressionStream object *ds* and a *chunk*, runs these steps:
180-
1. If *chunk* is not a {{BufferSource}} type, then return <a>a promise rejected with</a> a TypeError.
181-
1. Let *buffer* be the result of decompressing *chunk* with *ds*'s <a for=DecompressionStream>format</a> and <a for=DecompressionStream>context</a>. If this results in an error, then return <a>a promise rejected with</a> a TypeError.
182-
1. Let *controller* be *ds*'s <a>transform</a>.\[[TransformStreamController]].
183-
1. If *buffer* is empty, return <a>a promise resolved with</a> undefined.
184-
1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays.
185-
1. For each Uint8Array *array*, call <a abstract-op>TransformStreamDefaultControllerEnqueue</a>(*controller*, *array*).
186-
1. Return <a>a promise resolved with</a> undefined.
148+
The <dfn>decompress and enqueue a chunk</dfn> algorithm, given a {{DecompressionStream}} object *ds* and a *chunk*, runs these steps:
149+
1. If *chunk* is not a {{BufferSource}} type, then throw a {{TypeError}}.
150+
1. Let *buffer* be the result of decompressing *chunk* with *ds*'s <a for=DecompressionStream>format</a> and <a for=DecompressionStream>context</a>. If this results in an error, then throw a {{TypeError}}.
151+
1. If *buffer* is empty, return.
152+
1. Split *buffer* into one or more non-empty pieces and convert them into {{Uint8Array}}s.
153+
1. For each {{Uint8Array}} *array*, [=TransformStream/enqueue=] *array* in *ds*'s [=GenericTransformStream/transform=].
187154

188-
The <dfn>decompress flush and enqueue</dfn> algorithm, which handles the end of data from the input ReadableStream object, given a DecompressionStream object *ds*, runs these steps:
155+
The <dfn>decompress flush and enqueue</dfn> algorithm, which handles the end of data from the input {{ReadableStream}} object, given a {{DecompressionStream}} object *ds*, runs these steps:
189156

190157
1. Let *buffer* be the result of decompressing an empty input with *ds*'s <a for=DecompressionStream>format</a> and <a for=DecompressionStream>context</a>, with the finish flag.
191-
1. If the end of the compressed input has not been reached, return <a>a promise rejected with</a> a TypeError.
192-
1. If *buffer* is empty, return <a>a promise resolved with</a> undefined.
193-
1. Split *buffer* into one or more non-empty pieces and convert them into Uint8Arrays.
194-
1. For each Uint8Array *array*, call <a abstract-op>TransformStreamDefaultControllerEnqueue</a>(*controller*, *array*).
195-
1. Return <a>a promise resolved with</a> undefined.
158+
1. If the end of the compressed input has not been reached, then throw a {{TypeError}}.
159+
1. If *buffer* is empty, return.
160+
1. Split *buffer* into one or more non-empty pieces and convert them into {{Uint8Array}}s.
161+
1. For each {{Uint8Array}} *array*, [=TransformStream/enqueue=] *array* in *ds*'s [=GenericTransformStream/transform=].
196162

197163

198164
# Privacy and Security Considerations # {#privacy-security}

0 commit comments

Comments
 (0)