File tree Expand file tree Collapse file tree 1 file changed +5
-23
lines changed Expand file tree Collapse file tree 1 file changed +5
-23
lines changed Original file line number Diff line number Diff line change @@ -93,31 +93,13 @@ there are a number of benefits to a built-in capability:
93
93
const compressedReadableStream = inputReadableStream .pipeThrough (new CompressionStream (' gzip' ));
94
94
```
95
95
96
- ### Deflate-compress an ArrayBuffer to a Uint8Array
96
+ ### Deflate-compress an ArrayBuffer
97
97
98
98
``` javascript
99
- async function compressArrayBuffer (input ) {
100
- const cs = new CompressionStream (' deflate' );
101
- const writer = cs .writable .getWriter ();
102
- writer .write (input);
103
- writer .close ();
104
- const output = [];
105
- const reader = cs .readable .getReader ();
106
- let totalSize = 0 ;
107
- while (true ) {
108
- const { value , done } = await reader .read ();
109
- if (done)
110
- break ;
111
- output .push (value);
112
- totalSize += value .byteLength ;
113
- }
114
- const concatenated = new Uint8Array (totalSize);
115
- let offset = 0 ;
116
- for (const array of output) {
117
- concatenated .set (array, offset);
118
- offset += array .byteLength ;
119
- }
120
- return concatenated;
99
+ function compressArrayBuffer (input ) {
100
+ const stream = new Response (input).body
101
+ .pipeThrough (new CompressionStream (' deflate' ));
102
+ return new Response (stream).arrayBuffer ();
121
103
}
122
104
```
123
105
You can’t perform that action at this time.
0 commit comments