zlib-streams 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/build/7zip/Archive/Zip/ZipAddCommon.o +0 -0
- package/build/7zip/Archive/Zip/ZipHandler.o +0 -0
- package/build/7zip/Archive/Zip/ZipHandlerOut.o +0 -0
- package/build/7zip/Archive/Zip/ZipIn.o +0 -0
- package/build/7zip/Archive/Zip/ZipItem.o +0 -0
- package/build/7zip/Archive/Zip/ZipOut.o +0 -0
- package/build/7zip/Archive/Zip/ZipRegister.o +0 -0
- package/build/7zip/Archive/Zip/ZipUpdate.o +0 -0
- package/build/7zip/Common/CWrappers.o +0 -0
- package/build/7zip/Common/CreateCoder.o +0 -0
- package/build/7zip/Common/FileStreams.o +0 -0
- package/build/7zip/Common/FilterCoder.o +0 -0
- package/build/7zip/Common/InBuffer.o +0 -0
- package/build/7zip/Common/InOutTempBuffer.o +0 -0
- package/build/7zip/Common/OffsetStream.o +0 -0
- package/build/7zip/Common/OutBuffer.o +0 -0
- package/build/7zip/Common/OutMemStream.o +0 -0
- package/build/7zip/Common/StreamObjects.o +0 -0
- package/build/7zip/Common/StreamUtils.o +0 -0
- package/build/7zip/Compress/CopyCoder.o +0 -0
- package/build/7zip/Compress/Deflate64Register.o +0 -0
- package/build/7zip/Compress/DeflateDecoder.o +0 -0
- package/build/7zip/Compress/DeflateEncoder.o +0 -0
- package/build/7zip/Compress/DeflateRegister.o +0 -0
- package/build/7zip/Compress/LzOutWindow.o +0 -0
- package/build/Common/IntToString.o +0 -0
- package/build/Common/MyString.o +0 -0
- package/build/Common/MyWindows.o +0 -0
- package/build/Common/StringConvert.o +0 -0
- package/build/Common/UTFConvert.o +0 -0
- package/build/Windows/FileFind.o +0 -0
- package/build/Windows/FileIO.o +0 -0
- package/build/Windows/FileName.o +0 -0
- package/build/debug/src/inflate9.d +9 -0
- package/build/debug/src/inflate9.o +0 -0
- package/build/debug/src/zlib/adler32.d +5 -0
- package/build/debug/src/zlib/adler32.o +0 -0
- package/build/debug/src/zlib/contrib/infback9/infback9.d +13 -0
- package/build/debug/src/zlib/contrib/infback9/infback9.o +0 -0
- package/build/debug/src/zlib/contrib/infback9/inftree9.d +7 -0
- package/build/debug/src/zlib/contrib/infback9/inftree9.o +0 -0
- package/build/debug/src/zlib/crc32.d +6 -0
- package/build/debug/src/zlib/crc32.o +0 -0
- package/build/debug/src/zlib/infback.d +10 -0
- package/build/debug/src/zlib/infback.o +0 -0
- package/build/debug/src/zlib/inffast.d +9 -0
- package/build/debug/src/zlib/inffast.o +0 -0
- package/build/debug/src/zlib/inflate.d +10 -0
- package/build/debug/src/zlib/inflate.o +0 -0
- package/build/debug/src/zlib/inftrees.d +6 -0
- package/build/debug/src/zlib/inftrees.o +0 -0
- package/build/debug/src/zlib/trees.d +7 -0
- package/build/debug/src/zlib/trees.o +0 -0
- package/build/debug/src/zlib/zutil.d +6 -0
- package/build/debug/src/zlib/zutil.o +0 -0
- package/build/src/inflate9.d +9 -0
- package/build/src/inflate9.o +0 -0
- package/build/src/zlib/adler32.d +5 -0
- package/build/src/zlib/adler32.o +0 -0
- package/build/src/zlib/contrib/infback9/infback9.d +13 -0
- package/build/src/zlib/contrib/infback9/infback9.o +0 -0
- package/build/src/zlib/contrib/infback9/inftree9.d +7 -0
- package/build/src/zlib/contrib/infback9/inftree9.o +0 -0
- package/build/src/zlib/crc32.d +6 -0
- package/build/src/zlib/crc32.o +0 -0
- package/build/src/zlib/infback.d +10 -0
- package/build/src/zlib/infback.o +0 -0
- package/build/src/zlib/inffast.d +9 -0
- package/build/src/zlib/inffast.o +0 -0
- package/build/src/zlib/inflate.d +10 -0
- package/build/src/zlib/inflate.o +0 -0
- package/build/src/zlib/inftrees.d +6 -0
- package/build/src/zlib/inftrees.o +0 -0
- package/build/src/zlib/trees.d +7 -0
- package/build/src/zlib/trees.o +0 -0
- package/build/src/zlib/zutil.d +6 -0
- package/build/src/zlib/zutil.o +0 -0
- package/dist/zlib-streams.js +17 -6
- package/dist/zlib-streams.wasm +0 -0
- package/package.json +1 -1
- package/src/README.md +1 -0
- package/src/inflate9.c +14 -4
- package/src/inflate9.h +1 -8
- package/src/wasm/api/zlib-streams.js +17 -6
- package/src/wasm/deflate_stream_wasm.c +6 -41
- package/src/wasm/inflate9_stream_wasm.c +7 -51
- package/src/wasm/inflate_stream_wasm.c +7 -50
- package/src/wasm/wasm_stream_common.c +63 -0
- package/src/wasm/wasm_stream_common.h +26 -0
- package/tmp/all_runs/roundtrip_input.txt +3 -0
- package/tmp/all_runs/roundtrip_input1.txt +3 -0
- package/tmp/all_runs/roundtrip_input3.bin +0 -0
- package/tmp/out_ref.bin +10000 -0
- package/tmp/trace_ref.log +2 -0
package/Makefile
CHANGED
|
@@ -129,7 +129,7 @@ ci:
|
|
|
129
129
|
# -----------------------------------------------------------------------------
|
|
130
130
|
EMCC ?= emsdk/upstream/emscripten/emcc
|
|
131
131
|
|
|
132
|
-
WASM_SRCS = src/wasm/inflate9_stream_wasm.c src/wasm/inflate_stream_wasm.c src/wasm/deflate_stream_wasm.c src/wasm/allocator.c src/inflate9.c \
|
|
132
|
+
WASM_SRCS = src/wasm/inflate9_stream_wasm.c src/wasm/inflate_stream_wasm.c src/wasm/deflate_stream_wasm.c src/wasm/wasm_stream_common.c src/wasm/allocator.c src/inflate9.c \
|
|
133
133
|
src/zlib/contrib/infback9/inftree9.c \
|
|
134
134
|
src/zlib/inffast.c src/zlib/inflate.c src/zlib/inftrees.c src/zlib/zutil.c \
|
|
135
135
|
src/zlib/crc32.c src/zlib/adler32.c src/zlib/trees.c src/zlib/deflate.c
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
build/debug/src/inflate9.o: src/inflate9.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/contrib/infback9/inftree9.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
build/debug/src/zlib/contrib/infback9/infback9.o: \
|
|
2
|
+
src/zlib/contrib/infback9/infback9.c src/zlib/zutil.h src/zlib/zlib.h \
|
|
3
|
+
src/zlib/zconf.h src/zlib/contrib/infback9/infback9.h \
|
|
4
|
+
src/zlib/contrib/infback9/inftree9.h \
|
|
5
|
+
src/zlib/contrib/infback9/inflate9.h \
|
|
6
|
+
src/zlib/contrib/infback9/inffix9.h
|
|
7
|
+
src/zlib/zutil.h:
|
|
8
|
+
src/zlib/zlib.h:
|
|
9
|
+
src/zlib/zconf.h:
|
|
10
|
+
src/zlib/contrib/infback9/infback9.h:
|
|
11
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
12
|
+
src/zlib/contrib/infback9/inflate9.h:
|
|
13
|
+
src/zlib/contrib/infback9/inffix9.h:
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
build/debug/src/zlib/contrib/infback9/inftree9.o: \
|
|
2
|
+
src/zlib/contrib/infback9/inftree9.c src/zlib/zutil.h src/zlib/zlib.h \
|
|
3
|
+
src/zlib/zconf.h src/zlib/contrib/infback9/inftree9.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
build/debug/src/zlib/infback.o: src/zlib/infback.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
10
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
build/debug/src/zlib/inffast.o: src/zlib/inffast.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
build/debug/src/zlib/inflate.o: src/zlib/inflate.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
10
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
build/src/inflate9.o: src/inflate9.c src/zlib/zutil.h src/zlib/zlib.h \
|
|
2
|
+
src/zlib/zconf.h src/zlib/contrib/infback9/inftree9.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
build/src/zlib/contrib/infback9/infback9.o: \
|
|
2
|
+
src/zlib/contrib/infback9/infback9.c src/zlib/zutil.h src/zlib/zlib.h \
|
|
3
|
+
src/zlib/zconf.h src/zlib/contrib/infback9/infback9.h \
|
|
4
|
+
src/zlib/contrib/infback9/inftree9.h \
|
|
5
|
+
src/zlib/contrib/infback9/inflate9.h \
|
|
6
|
+
src/zlib/contrib/infback9/inffix9.h
|
|
7
|
+
src/zlib/zutil.h:
|
|
8
|
+
src/zlib/zlib.h:
|
|
9
|
+
src/zlib/zconf.h:
|
|
10
|
+
src/zlib/contrib/infback9/infback9.h:
|
|
11
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
12
|
+
src/zlib/contrib/infback9/inflate9.h:
|
|
13
|
+
src/zlib/contrib/infback9/inffix9.h:
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
build/src/zlib/contrib/infback9/inftree9.o: \
|
|
2
|
+
src/zlib/contrib/infback9/inftree9.c src/zlib/zutil.h src/zlib/zlib.h \
|
|
3
|
+
src/zlib/zconf.h src/zlib/contrib/infback9/inftree9.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/contrib/infback9/inftree9.h:
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
build/src/zlib/infback.o: src/zlib/infback.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
10
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
build/src/zlib/inffast.o: src/zlib/inffast.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
build/src/zlib/inflate.o: src/zlib/inflate.c src/zlib/zutil.h \
|
|
2
|
+
src/zlib/zlib.h src/zlib/zconf.h src/zlib/inftrees.h \
|
|
3
|
+
src/zlib/inflate.h src/zlib/inffast.h src/zlib/inffixed.h
|
|
4
|
+
src/zlib/zutil.h:
|
|
5
|
+
src/zlib/zlib.h:
|
|
6
|
+
src/zlib/zconf.h:
|
|
7
|
+
src/zlib/inftrees.h:
|
|
8
|
+
src/zlib/inflate.h:
|
|
9
|
+
src/zlib/inffast.h:
|
|
10
|
+
src/zlib/inffixed.h:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/zlib-streams.js
CHANGED
|
@@ -6,6 +6,10 @@ let wasm, malloc, free, memory;
|
|
|
6
6
|
export function setWasmExports(wasmAPI) {
|
|
7
7
|
wasm = wasmAPI;
|
|
8
8
|
({ malloc, free, memory } = wasm);
|
|
9
|
+
if (typeof malloc !== "function" || typeof free !== "function" || !memory) {
|
|
10
|
+
wasm = malloc = free = memory = null;
|
|
11
|
+
throw new Error("Invalid WASM module");
|
|
12
|
+
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
function _make(isCompress, type, options = {}) {
|
|
@@ -77,14 +81,18 @@ function _make(isCompress, type, options = {}) {
|
|
|
77
81
|
}
|
|
78
82
|
heap.set(buffer.subarray(offset, offset + toRead), this.in);
|
|
79
83
|
const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
|
|
80
|
-
if (!isCompress && result < 0) {
|
|
81
|
-
throw new Error("process error:" + result);
|
|
82
|
-
}
|
|
83
84
|
const prod = result & 0x00ffffff;
|
|
84
85
|
if (prod) {
|
|
85
86
|
scratch.set(heap.subarray(out, out + prod), 0);
|
|
86
87
|
controller.enqueue(scratch.slice(0, prod));
|
|
87
88
|
}
|
|
89
|
+
if (!isCompress) {
|
|
90
|
+
const code = (result >> 24) & 0xff;
|
|
91
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
92
|
+
if (signedCode < 0) {
|
|
93
|
+
throw new Error("process error:" + signedCode);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
88
96
|
const consumed = last_consumed(this.streamHandle);
|
|
89
97
|
if (consumed === 0) {
|
|
90
98
|
break;
|
|
@@ -112,11 +120,14 @@ function _make(isCompress, type, options = {}) {
|
|
|
112
120
|
const scratch = this._scratch;
|
|
113
121
|
while (true) {
|
|
114
122
|
const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
|
|
115
|
-
if (!isCompress && result < 0) {
|
|
116
|
-
throw new Error("process error:" + result);
|
|
117
|
-
}
|
|
118
123
|
const produced = result & 0x00ffffff;
|
|
119
124
|
const code = (result >> 24) & 0xff;
|
|
125
|
+
if (!isCompress) {
|
|
126
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
127
|
+
if (signedCode < 0) {
|
|
128
|
+
throw new Error("process error:" + signedCode);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
120
131
|
if (produced) {
|
|
121
132
|
scratch.set(heap.subarray(out, out + produced), 0);
|
|
122
133
|
controller.enqueue(scratch.slice(0, produced));
|
package/dist/zlib-streams.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "WASM-based Compression Streams API implementation using zlib, with support for deflate64 decompression.",
|
|
4
4
|
"author": "Gildas Lormeau",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.5",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"deflate",
|
package/src/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See https://github.com/gildas-lormeau/inflate9.c
|
package/src/inflate9.c
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
#include "zutil.h"
|
|
7
7
|
#include "inftree9.h"
|
|
8
8
|
#include "inflate.h"
|
|
9
|
-
#include "infback9.h"
|
|
10
9
|
|
|
11
10
|
#ifdef MAKEFIXED
|
|
12
11
|
#ifndef BUILDFIXED
|
|
@@ -691,7 +690,7 @@ int ZEXPORT inflate9(z_streamp strm, int flush) {
|
|
|
691
690
|
state->mode = BAD;
|
|
692
691
|
break;
|
|
693
692
|
}
|
|
694
|
-
state->extra = (unsigned)(here.op) &
|
|
693
|
+
state->extra = (unsigned)(here.op) & 31;
|
|
695
694
|
state->mode = LENEXT;
|
|
696
695
|
/* fallthrough */
|
|
697
696
|
case LENEXT:
|
|
@@ -765,7 +764,7 @@ int ZEXPORT inflate9(z_streamp strm, int flush) {
|
|
|
765
764
|
break;
|
|
766
765
|
}
|
|
767
766
|
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
|
768
|
-
Trace((stderr, "
|
|
767
|
+
Trace((stderr, "inflate9.c too far\n"));
|
|
769
768
|
copy -= state->whave;
|
|
770
769
|
if (copy > state->length)
|
|
771
770
|
copy = state->length;
|
|
@@ -846,4 +845,15 @@ inf_leave:
|
|
|
846
845
|
return ret;
|
|
847
846
|
}
|
|
848
847
|
|
|
849
|
-
int ZEXPORT inflate9End(z_streamp strm) {
|
|
848
|
+
int ZEXPORT inflate9End(z_streamp strm) {
|
|
849
|
+
struct inflate_state FAR *state;
|
|
850
|
+
if (inflateStateCheck(strm))
|
|
851
|
+
return Z_STREAM_ERROR;
|
|
852
|
+
state = (struct inflate_state FAR *)strm->state;
|
|
853
|
+
if (state->window != Z_NULL)
|
|
854
|
+
ZFREE(strm, state->window);
|
|
855
|
+
ZFREE(strm, strm->state);
|
|
856
|
+
strm->state = Z_NULL;
|
|
857
|
+
Tracev((stderr, "inflate: end\n"));
|
|
858
|
+
return Z_OK;
|
|
859
|
+
}
|
package/src/inflate9.h
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
#ifndef ZLIB_INFLATE9_H_COMPAT
|
|
2
|
-
#define ZLIB_INFLATE9_H_COMPAT
|
|
3
|
-
|
|
4
1
|
#include "zutil.h"
|
|
5
|
-
#include "inftree9.h"
|
|
6
|
-
#include "inflate.h"
|
|
7
2
|
|
|
8
3
|
int ZEXPORT inflate9Init(z_streamp strm);
|
|
9
4
|
int ZEXPORT inflate9(z_streamp strm, int flush);
|
|
@@ -11,6 +6,4 @@ int ZEXPORT inflate9End(z_streamp strm);
|
|
|
11
6
|
int ZEXPORT inflate9Init_(z_streamp strm, const char *version, int stream_size);
|
|
12
7
|
int ZEXPORT inflate9Init2_(z_streamp strm, int windowBits, const char *version,
|
|
13
8
|
int stream_size);
|
|
14
|
-
int ZEXPORT inflate9Reset2(z_streamp strm, int windowBits);
|
|
15
|
-
|
|
16
|
-
#endif /* ZLIB_INFLATE9_H_COMPAT */
|
|
9
|
+
int ZEXPORT inflate9Reset2(z_streamp strm, int windowBits);
|
|
@@ -6,6 +6,10 @@ let wasm, malloc, free, memory;
|
|
|
6
6
|
export function setWasmExports(wasmAPI) {
|
|
7
7
|
wasm = wasmAPI;
|
|
8
8
|
({ malloc, free, memory } = wasm);
|
|
9
|
+
if (typeof malloc !== "function" || typeof free !== "function" || !memory) {
|
|
10
|
+
wasm = malloc = free = memory = null;
|
|
11
|
+
throw new Error("Invalid WASM module");
|
|
12
|
+
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
function _make(isCompress, type, options = {}) {
|
|
@@ -77,14 +81,18 @@ function _make(isCompress, type, options = {}) {
|
|
|
77
81
|
}
|
|
78
82
|
heap.set(buffer.subarray(offset, offset + toRead), this.in);
|
|
79
83
|
const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
|
|
80
|
-
if (!isCompress && result < 0) {
|
|
81
|
-
throw new Error("process error:" + result);
|
|
82
|
-
}
|
|
83
84
|
const prod = result & 0x00ffffff;
|
|
84
85
|
if (prod) {
|
|
85
86
|
scratch.set(heap.subarray(out, out + prod), 0);
|
|
86
87
|
controller.enqueue(scratch.slice(0, prod));
|
|
87
88
|
}
|
|
89
|
+
if (!isCompress) {
|
|
90
|
+
const code = (result >> 24) & 0xff;
|
|
91
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
92
|
+
if (signedCode < 0) {
|
|
93
|
+
throw new Error("process error:" + signedCode);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
88
96
|
const consumed = last_consumed(this.streamHandle);
|
|
89
97
|
if (consumed === 0) {
|
|
90
98
|
break;
|
|
@@ -112,11 +120,14 @@ function _make(isCompress, type, options = {}) {
|
|
|
112
120
|
const scratch = this._scratch;
|
|
113
121
|
while (true) {
|
|
114
122
|
const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
|
|
115
|
-
if (!isCompress && result < 0) {
|
|
116
|
-
throw new Error("process error:" + result);
|
|
117
|
-
}
|
|
118
123
|
const produced = result & 0x00ffffff;
|
|
119
124
|
const code = (result >> 24) & 0xff;
|
|
125
|
+
if (!isCompress) {
|
|
126
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
127
|
+
if (signedCode < 0) {
|
|
128
|
+
throw new Error("process error:" + signedCode);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
120
131
|
if (produced) {
|
|
121
132
|
scratch.set(heap.subarray(out, out + produced), 0);
|
|
122
133
|
controller.enqueue(scratch.slice(0, produced));
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <stdint.h>
|
|
4
4
|
#include "zlib.h"
|
|
5
5
|
#include "allocator.h"
|
|
6
|
+
#include "wasm_stream_common.h"
|
|
6
7
|
|
|
7
8
|
#ifndef RAW_WBITS
|
|
8
9
|
#if defined(MAX_WBITS)
|
|
@@ -13,24 +14,10 @@
|
|
|
13
14
|
#endif
|
|
14
15
|
|
|
15
16
|
struct wasm_deflate_ctx {
|
|
16
|
-
|
|
17
|
-
unsigned char *inbuf;
|
|
18
|
-
unsigned inbuf_sz;
|
|
19
|
-
unsigned last_consumed;
|
|
17
|
+
WASM_STREAM_COMMON_FIELDS
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
unsigned deflate_new(void) {
|
|
23
|
-
struct wasm_deflate_ctx *c = (struct wasm_deflate_ctx *)malloc(sizeof(*c));
|
|
24
|
-
if (!c)
|
|
25
|
-
return 0;
|
|
26
|
-
memset(c, 0, sizeof(*c));
|
|
27
|
-
c->strm.zalloc = my_zalloc;
|
|
28
|
-
c->strm.zfree = my_zfree;
|
|
29
|
-
c->strm.opaque = Z_NULL;
|
|
30
|
-
c->inbuf = NULL;
|
|
31
|
-
c->inbuf_sz = 0;
|
|
32
|
-
return (unsigned)(uintptr_t)c;
|
|
33
|
-
}
|
|
20
|
+
unsigned deflate_new(void) { return wasm_stream_new(); }
|
|
34
21
|
|
|
35
22
|
int deflate_init(unsigned zptr, int level) {
|
|
36
23
|
struct wasm_deflate_ctx *c = (struct wasm_deflate_ctx *)(uintptr_t)zptr;
|
|
@@ -63,27 +50,8 @@ int deflate_init_gzip(unsigned zptr, int level) {
|
|
|
63
50
|
|
|
64
51
|
int deflate_process(unsigned zptr, unsigned in_ptr, unsigned in_len,
|
|
65
52
|
unsigned out_ptr, unsigned out_len, int flush) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return Z_STREAM_ERROR;
|
|
69
|
-
if (in_len > c->inbuf_sz) {
|
|
70
|
-
unsigned char *nb = (unsigned char *)realloc(c->inbuf, in_len);
|
|
71
|
-
if (!nb)
|
|
72
|
-
return Z_MEM_ERROR;
|
|
73
|
-
c->inbuf = nb;
|
|
74
|
-
c->inbuf_sz = in_len;
|
|
75
|
-
}
|
|
76
|
-
memcpy(c->inbuf, (unsigned char *)(uintptr_t)in_ptr, in_len);
|
|
77
|
-
c->strm.next_in = c->inbuf;
|
|
78
|
-
c->strm.avail_in = in_len;
|
|
79
|
-
c->strm.next_out = (unsigned char *)(uintptr_t)out_ptr;
|
|
80
|
-
c->strm.avail_out = out_len;
|
|
81
|
-
|
|
82
|
-
int ret = deflate(&c->strm, flush);
|
|
83
|
-
int produced = (int)(out_len - c->strm.avail_out);
|
|
84
|
-
c->last_consumed = (unsigned)(in_len - c->strm.avail_in);
|
|
85
|
-
int code = ret & 0xff;
|
|
86
|
-
return (produced & 0x00ffffff) | ((code & 0xff) << 24);
|
|
53
|
+
return wasm_stream_process_common(zptr, in_ptr, in_len, out_ptr, out_len,
|
|
54
|
+
flush, deflate);
|
|
87
55
|
}
|
|
88
56
|
|
|
89
57
|
int deflate_end(unsigned zptr) {
|
|
@@ -97,8 +65,5 @@ int deflate_end(unsigned zptr) {
|
|
|
97
65
|
}
|
|
98
66
|
|
|
99
67
|
unsigned deflate_last_consumed(unsigned zptr) {
|
|
100
|
-
|
|
101
|
-
if (!c)
|
|
102
|
-
return 0;
|
|
103
|
-
return c->last_consumed;
|
|
68
|
+
return wasm_stream_last_consumed(zptr);
|
|
104
69
|
}
|