Skip to content

Commit 2152319

Browse files
rollback
1 parent a86919b commit 2152319

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

lib/core/streams/zlib-wasm/zlib-streams.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,45 @@ export function setWasmExports(wasmAPI) {
4242
function _make(isCompress, type, options = {}) {
4343
const level = (typeof options.level === "number") ? options.level : -1;
4444
const outBufferSize = (typeof options.outBuffer === "number") ? options.outBuffer : 64 * 1024;
45-
const _inBufferSize = (typeof options._inBufferSize === "number") ? options._inBufferSize : 64 * 1024;
45+
const inBufferSize = (typeof options.inBufferSize === "number") ? options.inBufferSize : 64 * 1024;
4646

4747
return new TransformStream({
4848
start() {
4949
let result;
50-
this._out = malloc(outBufferSize);
51-
this._in = malloc(_inBufferSize);
52-
this._inBufferSize = _inBufferSize;
50+
this.out = malloc(outBufferSize);
51+
this.in = malloc(inBufferSize);
52+
this.inBufferSize = inBufferSize;
5353
this._scratch = new Uint8Array(outBufferSize);
5454
if (isCompress) {
5555
this._process = wasm.deflate_process;
5656
this._last_consumed = wasm.deflate_last_consumed;
5757
this._end = wasm.deflate_end;
58-
this._streamHandle = wasm.deflate_new();
58+
this.streamHandle = wasm.deflate_new();
5959
if (type === "gzip") {
60-
result = wasm.deflate_init_gzip(this._streamHandle, level);
60+
result = wasm.deflate_init_gzip(this.streamHandle, level);
6161
} else if (type === "deflate-raw") {
62-
result = wasm.deflate_init_raw(this._streamHandle, level);
62+
result = wasm.deflate_init_raw(this.streamHandle, level);
6363
} else {
64-
result = wasm.deflate_init(this._streamHandle, level);
64+
result = wasm.deflate_init(this.streamHandle, level);
6565
}
6666
} else {
6767
if (type === "deflate64-raw") {
6868
this._process = wasm.inflate9_process;
6969
this._last_consumed = wasm.inflate9_last_consumed;
7070
this._end = wasm.inflate9_end;
71-
this._streamHandle = wasm.inflate9_new();
72-
result = wasm.inflate9_init_raw(this._streamHandle);
71+
this.streamHandle = wasm.inflate9_new();
72+
result = wasm.inflate9_init_raw(this.streamHandle);
7373
} else {
7474
this._process = wasm.inflate_process;
7575
this._last_consumed = wasm.inflate_last_consumed;
7676
this._end = wasm.inflate_end;
77-
this._streamHandle = wasm.inflate_new();
77+
this.streamHandle = wasm.inflate_new();
7878
if (type === "deflate-raw") {
79-
result = wasm.inflate_init_raw(this._streamHandle);
79+
result = wasm.inflate_init_raw(this.streamHandle);
8080
} else if (type === "gzip") {
81-
result = wasm.inflate_init_gzip(this._streamHandle);
81+
result = wasm.inflate_init_gzip(this.streamHandle);
8282
} else {
83-
result = wasm.inflate_init(this._streamHandle);
83+
result = wasm.inflate_init(this.streamHandle);
8484
}
8585
}
8686
}
@@ -94,20 +94,20 @@ function _make(isCompress, type, options = {}) {
9494
const heap = new Uint8Array(memory.buffer);
9595
const process = this._process;
9696
const last_consumed = this._last_consumed;
97-
const out = this._out;
97+
const out = this.out;
9898
const scratch = this._scratch;
9999
let offset = 0;
100100
while (offset < buffer.length) {
101101
const toRead = Math.min(buffer.length - offset, 32 * 1024);
102-
if (!this._in || this._inBufferSize < toRead) {
103-
if (this._in && free) {
104-
free(this._in);
102+
if (!this.in || this.inBufferSize < toRead) {
103+
if (this.in && free) {
104+
free(this.in);
105105
}
106-
this._in = malloc(toRead);
107-
this._inBufferSize = toRead;
106+
this.in = malloc(toRead);
107+
this.inBufferSize = toRead;
108108
}
109-
heap.set(buffer.subarray(offset, offset + toRead), this._in);
110-
const result = process(this._streamHandle, this._in, toRead, out, outBufferSize, 0);
109+
heap.set(buffer.subarray(offset, offset + toRead), this.in);
110+
const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
111111
if (!isCompress && result < 0) {
112112
throw new Error("process error:" + result);
113113
}
@@ -116,21 +116,21 @@ function _make(isCompress, type, options = {}) {
116116
scratch.set(heap.subarray(out, out + prod), 0);
117117
controller.enqueue(scratch.slice(0, prod));
118118
}
119-
const consumed = last_consumed(this._streamHandle);
119+
const consumed = last_consumed(this.streamHandle);
120120
if (consumed === 0) {
121121
break;
122122
}
123123
offset += consumed;
124124
}
125125
} catch (error) {
126-
if (this._end && this._streamHandle) {
127-
this._end(this._streamHandle);
126+
if (this._end && this.streamHandle) {
127+
this._end(this.streamHandle);
128128
}
129-
if (this._in && free) {
130-
free(this._in);
129+
if (this.in && free) {
130+
free(this.in);
131131
}
132-
if (this._out && free) {
133-
free(this._out);
132+
if (this.out && free) {
133+
free(this.out);
134134
}
135135
controller.error(error);
136136
}
@@ -139,17 +139,17 @@ function _make(isCompress, type, options = {}) {
139139
try {
140140
const heap = new Uint8Array(memory.buffer);
141141
const process = this._process;
142-
const _out = this._out;
142+
const out = this.out;
143143
const scratch = this._scratch;
144144
while (true) {
145-
const result = process(this._streamHandle, 0, 0, _out, outBufferSize, 4);
145+
const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
146146
if (!isCompress && result < 0) {
147147
throw new Error("process error:" + result);
148148
}
149149
const produced = result & 0x00ffffff;
150150
const code = (result >> 24) & 0xff;
151151
if (produced) {
152-
scratch.set(heap.subarray(_out, _out + produced), 0);
152+
scratch.set(heap.subarray(out, out + produced), 0);
153153
controller.enqueue(scratch.slice(0, produced));
154154
}
155155
if (code === 1 || produced === 0) {
@@ -159,17 +159,17 @@ function _make(isCompress, type, options = {}) {
159159
} catch (error) {
160160
controller.error(error);
161161
} finally {
162-
if (this._end && this._streamHandle) {
163-
const result = this._end(this._streamHandle);
162+
if (this._end && this.streamHandle) {
163+
const result = this._end(this.streamHandle);
164164
if (result !== 0) {
165165
controller.error(new Error("end error:" + result));
166166
}
167167
}
168-
if (this._in && free) {
169-
free(this._in);
168+
if (this.in && free) {
169+
free(this.in);
170170
}
171-
if (this._out && free) {
172-
free(this._out);
171+
if (this.out && free) {
172+
free(this.out);
173173
}
174174
}
175175
}

0 commit comments

Comments
 (0)