zlib-streams 1.0.3 → 1.0.4
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 +13 -3
- 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/out_ref.bin +10000 -0
- package/tmp/trace_ref.log +2 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#include <stdint.h>
|
|
4
4
|
#include "zlib.h"
|
|
5
5
|
#include "inflate9.h"
|
|
6
|
-
#include "
|
|
6
|
+
#include "wasm_stream_common.h"
|
|
7
7
|
#ifndef DEFLATE64_WBITS
|
|
8
8
|
#if defined(MAX_WBITS) && (MAX_WBITS >= 16)
|
|
9
9
|
#define DEFLATE64_WBITS MAX_WBITS
|
|
@@ -13,24 +13,10 @@
|
|
|
13
13
|
#endif
|
|
14
14
|
|
|
15
15
|
struct wasm_inflate9_ctx {
|
|
16
|
-
|
|
17
|
-
unsigned char *inbuf;
|
|
18
|
-
unsigned inbuf_sz;
|
|
19
|
-
unsigned last_consumed;
|
|
16
|
+
WASM_STREAM_COMMON_FIELDS;
|
|
20
17
|
};
|
|
21
18
|
|
|
22
|
-
unsigned inflate9_new(void) {
|
|
23
|
-
struct wasm_inflate9_ctx *c = (struct wasm_inflate9_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
|
-
}
|
|
19
|
+
unsigned inflate9_new(void) { return wasm_stream_new(); }
|
|
34
20
|
|
|
35
21
|
int inflate9_init(unsigned zptr) {
|
|
36
22
|
struct wasm_inflate9_ctx *c = (struct wasm_inflate9_ctx *)(uintptr_t)zptr;
|
|
@@ -49,42 +35,12 @@ int inflate9_init_raw(unsigned zptr) {
|
|
|
49
35
|
|
|
50
36
|
int inflate9_process(unsigned zptr, unsigned in_ptr, unsigned in_len,
|
|
51
37
|
unsigned out_ptr, unsigned out_len, int flush) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return Z_STREAM_ERROR;
|
|
55
|
-
if (in_len > c->inbuf_sz) {
|
|
56
|
-
unsigned char *nb = (unsigned char *)realloc(c->inbuf, in_len);
|
|
57
|
-
if (!nb)
|
|
58
|
-
return Z_MEM_ERROR;
|
|
59
|
-
c->inbuf = nb;
|
|
60
|
-
c->inbuf_sz = in_len;
|
|
61
|
-
}
|
|
62
|
-
memcpy(c->inbuf, (unsigned char *)(uintptr_t)in_ptr, in_len);
|
|
63
|
-
c->strm.next_in = c->inbuf;
|
|
64
|
-
c->strm.avail_in = in_len;
|
|
65
|
-
c->strm.next_out = (unsigned char *)(uintptr_t)out_ptr;
|
|
66
|
-
c->strm.avail_out = out_len;
|
|
67
|
-
|
|
68
|
-
int ret = inflate9(&c->strm, flush);
|
|
69
|
-
int produced = (int)(out_len - c->strm.avail_out);
|
|
70
|
-
c->last_consumed = (unsigned)(in_len - c->strm.avail_in);
|
|
71
|
-
int code = ret & 0xff;
|
|
72
|
-
return (produced & 0x00ffffff) | ((code & 0xff) << 24);
|
|
38
|
+
return wasm_stream_process_common(zptr, in_ptr, in_len, out_ptr, out_len,
|
|
39
|
+
flush, inflate9);
|
|
73
40
|
}
|
|
74
41
|
|
|
75
|
-
int inflate9_end(unsigned zptr) {
|
|
76
|
-
struct wasm_inflate9_ctx *c = (struct wasm_inflate9_ctx *)(uintptr_t)zptr;
|
|
77
|
-
if (!c)
|
|
78
|
-
return Z_STREAM_ERROR;
|
|
79
|
-
int r = inflate9End(&c->strm);
|
|
80
|
-
free(c->inbuf);
|
|
81
|
-
free(c);
|
|
82
|
-
return r;
|
|
83
|
-
}
|
|
42
|
+
int inflate9_end(unsigned zptr) { return wasm_stream_end(zptr, inflate9End); }
|
|
84
43
|
|
|
85
44
|
unsigned inflate9_last_consumed(unsigned zptr) {
|
|
86
|
-
|
|
87
|
-
if (!c)
|
|
88
|
-
return 0;
|
|
89
|
-
return c->last_consumed;
|
|
45
|
+
return wasm_stream_last_consumed(zptr);
|
|
90
46
|
}
|
|
@@ -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_inflate_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 inflate_new(void) {
|
|
23
|
-
struct wasm_inflate_ctx *c = (struct wasm_inflate_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 = NULL;
|
|
30
|
-
c->inbuf = NULL;
|
|
31
|
-
c->inbuf_sz = 0;
|
|
32
|
-
return (unsigned)(uintptr_t)c;
|
|
33
|
-
}
|
|
20
|
+
unsigned inflate_new(void) { return wasm_stream_new(); }
|
|
34
21
|
|
|
35
22
|
int inflate_init(unsigned zptr) {
|
|
36
23
|
struct wasm_inflate_ctx *c = (struct wasm_inflate_ctx *)(uintptr_t)zptr;
|
|
@@ -59,42 +46,12 @@ int inflate_init_gzip(unsigned zptr) {
|
|
|
59
46
|
|
|
60
47
|
int inflate_process(unsigned zptr, unsigned in_ptr, unsigned in_len,
|
|
61
48
|
unsigned out_ptr, unsigned out_len, int flush) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return Z_STREAM_ERROR;
|
|
65
|
-
if (in_len > c->inbuf_sz) {
|
|
66
|
-
unsigned char *nb = (unsigned char *)realloc(c->inbuf, in_len);
|
|
67
|
-
if (!nb)
|
|
68
|
-
return Z_MEM_ERROR;
|
|
69
|
-
c->inbuf = nb;
|
|
70
|
-
c->inbuf_sz = in_len;
|
|
71
|
-
}
|
|
72
|
-
memcpy(c->inbuf, (unsigned char *)(uintptr_t)in_ptr, in_len);
|
|
73
|
-
c->strm.next_in = c->inbuf;
|
|
74
|
-
c->strm.avail_in = in_len;
|
|
75
|
-
c->strm.next_out = (unsigned char *)(uintptr_t)out_ptr;
|
|
76
|
-
c->strm.avail_out = out_len;
|
|
77
|
-
|
|
78
|
-
int ret = inflate(&c->strm, flush);
|
|
79
|
-
int produced = (int)(out_len - c->strm.avail_out);
|
|
80
|
-
c->last_consumed = (unsigned)(in_len - c->strm.avail_in);
|
|
81
|
-
int code = ret & 0xff;
|
|
82
|
-
return (produced & 0x00ffffff) | ((code & 0xff) << 24);
|
|
49
|
+
return wasm_stream_process_common(zptr, in_ptr, in_len, out_ptr, out_len,
|
|
50
|
+
flush, inflate);
|
|
83
51
|
}
|
|
84
52
|
|
|
85
|
-
int inflate_end(unsigned zptr) {
|
|
86
|
-
struct wasm_inflate_ctx *c = (struct wasm_inflate_ctx *)(uintptr_t)zptr;
|
|
87
|
-
if (!c)
|
|
88
|
-
return Z_STREAM_ERROR;
|
|
89
|
-
int r = inflateEnd(&c->strm);
|
|
90
|
-
free(c->inbuf);
|
|
91
|
-
free(c);
|
|
92
|
-
return r;
|
|
93
|
-
}
|
|
53
|
+
int inflate_end(unsigned zptr) { return wasm_stream_end(zptr, inflateEnd); }
|
|
94
54
|
|
|
95
55
|
unsigned inflate_last_consumed(unsigned zptr) {
|
|
96
|
-
|
|
97
|
-
if (!c)
|
|
98
|
-
return 0;
|
|
99
|
-
return c->last_consumed;
|
|
56
|
+
return wasm_stream_last_consumed(zptr);
|
|
100
57
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#include <stdlib.h>
|
|
2
|
+
#include <string.h>
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
#include "wasm_stream_common.h"
|
|
5
|
+
#include "allocator.h"
|
|
6
|
+
|
|
7
|
+
unsigned wasm_stream_new(void) {
|
|
8
|
+
struct wasm_stream_ctx *c = (struct wasm_stream_ctx *)malloc(sizeof(*c));
|
|
9
|
+
if (!c)
|
|
10
|
+
return 0;
|
|
11
|
+
memset(c, 0, sizeof(*c));
|
|
12
|
+
c->strm.zalloc = my_zalloc;
|
|
13
|
+
c->strm.zfree = my_zfree;
|
|
14
|
+
c->strm.opaque = Z_NULL;
|
|
15
|
+
c->inbuf = NULL;
|
|
16
|
+
c->inbuf_sz = 0;
|
|
17
|
+
return (unsigned)(uintptr_t)c;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
int wasm_stream_end(unsigned zptr, int (*end_func)(z_stream *)) {
|
|
21
|
+
struct wasm_stream_ctx *c = (struct wasm_stream_ctx *)(uintptr_t)zptr;
|
|
22
|
+
if (!c)
|
|
23
|
+
return Z_STREAM_ERROR;
|
|
24
|
+
int r = end_func(&c->strm);
|
|
25
|
+
free(c->inbuf);
|
|
26
|
+
free(c);
|
|
27
|
+
return r;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
unsigned wasm_stream_last_consumed(unsigned zptr) {
|
|
31
|
+
struct wasm_stream_ctx *c = (struct wasm_stream_ctx *)(uintptr_t)zptr;
|
|
32
|
+
if (!c)
|
|
33
|
+
return 0;
|
|
34
|
+
return c->last_consumed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
int wasm_stream_process_common(unsigned zptr, unsigned in_ptr, unsigned in_len,
|
|
38
|
+
unsigned out_ptr, unsigned out_len, int flush,
|
|
39
|
+
int (*process_func)(z_streamp, int)) {
|
|
40
|
+
struct wasm_stream_ctx *c = (struct wasm_stream_ctx *)(uintptr_t)zptr;
|
|
41
|
+
if (!c)
|
|
42
|
+
return Z_STREAM_ERROR;
|
|
43
|
+
|
|
44
|
+
if (in_len > c->inbuf_sz) {
|
|
45
|
+
unsigned char *nb = (unsigned char *)realloc(c->inbuf, in_len);
|
|
46
|
+
if (!nb)
|
|
47
|
+
return Z_MEM_ERROR;
|
|
48
|
+
c->inbuf = nb;
|
|
49
|
+
c->inbuf_sz = in_len;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
memcpy(c->inbuf, (unsigned char *)(uintptr_t)in_ptr, in_len);
|
|
53
|
+
c->strm.next_in = c->inbuf;
|
|
54
|
+
c->strm.avail_in = in_len;
|
|
55
|
+
c->strm.next_out = (unsigned char *)(uintptr_t)out_ptr;
|
|
56
|
+
c->strm.avail_out = out_len;
|
|
57
|
+
|
|
58
|
+
int ret = process_func(&c->strm, flush);
|
|
59
|
+
int produced = (int)(out_len - c->strm.avail_out);
|
|
60
|
+
c->last_consumed = (unsigned)(in_len - c->strm.avail_in);
|
|
61
|
+
int code = ret & 0xff;
|
|
62
|
+
return (produced & 0x00ffffff) | ((code & 0xff) << 24);
|
|
63
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef WASM_STREAM_COMMON_H
|
|
2
|
+
#define WASM_STREAM_COMMON_H
|
|
3
|
+
|
|
4
|
+
#include "zlib.h"
|
|
5
|
+
#include "allocator.h"
|
|
6
|
+
|
|
7
|
+
// Common fields for all WASM stream contexts
|
|
8
|
+
#define WASM_STREAM_COMMON_FIELDS \
|
|
9
|
+
z_stream strm; \
|
|
10
|
+
unsigned char *inbuf; \
|
|
11
|
+
unsigned inbuf_sz; \
|
|
12
|
+
unsigned last_consumed;
|
|
13
|
+
|
|
14
|
+
struct wasm_stream_ctx {
|
|
15
|
+
WASM_STREAM_COMMON_FIELDS;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Common function declarations
|
|
19
|
+
unsigned wasm_stream_new(void);
|
|
20
|
+
int wasm_stream_end(unsigned zptr, int (*end_func)(z_stream *));
|
|
21
|
+
unsigned wasm_stream_last_consumed(unsigned zptr);
|
|
22
|
+
int wasm_stream_process_common(unsigned zptr, unsigned in_ptr, unsigned in_len,
|
|
23
|
+
unsigned out_ptr, unsigned out_len, int flush,
|
|
24
|
+
int (*process_func)(z_stream *, int));
|
|
25
|
+
|
|
26
|
+
#endif // WASM_STREAM_COMMON_H
|