typenative 0.7.0 → 0.7.1

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.
Files changed (217) hide show
  1. package/bin/node/assert.js +2 -2
  2. package/bin/node/child_process.js +66 -8
  3. package/bin/node/fs.js +1012 -4
  4. package/bin/node/histogram.js +1991 -0
  5. package/bin/node/process.js +14 -2
  6. package/bin/node/sqlite.js +1488 -5
  7. package/bin/node/stream.js +2 -1
  8. package/bin/node/system_extra.js +3 -270
  9. package/bin/node/test.js +39 -1
  10. package/bin/node/test_report.js +47 -1
  11. package/bin/node/test_run.js +57 -2
  12. package/bin/node/util.js +8 -5
  13. package/bin/node/webassembly.js +20 -5
  14. package/bin/node/webview.js +3257 -244
  15. package/bin/node/zlib.js +118 -14
  16. package/bin/node/zlib_iter.js +585 -0
  17. package/bin/transpiler.js +1370 -258
  18. package/bin/version.js +1 -1
  19. package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
  20. package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
  21. package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
  22. package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
  23. package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
  24. package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
  25. package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
  26. package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
  27. package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
  28. package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
  29. package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
  30. package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
  31. package/package.json +10 -1
  32. package/types/tsconfig.json +17 -0
  33. package/types/typenative-npm.d.ts +492 -12
  34. package/types/typenative.d.ts +88 -2
  35. package/.gitattributes +0 -1
  36. package/.github/workflows/ci.yml +0 -68
  37. package/.github/workflows/npm-publish-github-packages.yml +0 -88
  38. package/CHANGELOG.md +0 -1746
  39. package/CONTRIBUTION.md +0 -133
  40. package/conformance.md +0 -1497
  41. package/examples/README.md +0 -114
  42. package/examples/angular-templates/README.md +0 -141
  43. package/examples/angular-templates/bench.mjs +0 -173
  44. package/examples/angular-templates/dom-type-globals.d.ts +0 -21
  45. package/examples/angular-templates/dom-type-stubs.ts +0 -21
  46. package/examples/angular-templates/main.ts +0 -135
  47. package/examples/angular-templates/parity.mjs +0 -157
  48. package/examples/angular-templates/run-node.mjs +0 -69
  49. package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
  50. package/examples/desktop-notes/README.md +0 -106
  51. package/examples/desktop-notes/bench.mjs +0 -125
  52. package/examples/desktop-notes/main.ts +0 -131
  53. package/examples/desktop-notes/package-lock.json +0 -726
  54. package/examples/desktop-notes/package.json +0 -9
  55. package/examples/desktop-notes/ui.ts +0 -176
  56. package/examples/dupe-finder/README.md +0 -78
  57. package/examples/dupe-finder/bench.mjs +0 -120
  58. package/examples/dupe-finder/main.ts +0 -87
  59. package/examples/fibonacci/README.md +0 -89
  60. package/examples/fibonacci/bench.mjs +0 -87
  61. package/examples/fibonacci/main.ts +0 -21
  62. package/examples/hello-world/README.md +0 -62
  63. package/examples/hello-world/bench.mjs +0 -66
  64. package/examples/hello-world/main.ts +0 -7
  65. package/examples/json-server/README.md +0 -132
  66. package/examples/json-server/bench.mjs +0 -263
  67. package/examples/json-server/main.ts +0 -67
  68. package/examples/mandelbrot-png/README.md +0 -63
  69. package/examples/mandelbrot-png/bench.mjs +0 -95
  70. package/examples/mandelbrot-png/main.ts +0 -98
  71. package/examples/mandelbrot-png/preview.png +0 -0
  72. package/examples/marked-cli/README.md +0 -174
  73. package/examples/marked-cli/bench.mjs +0 -178
  74. package/examples/marked-cli/main.ts +0 -410
  75. package/examples/marked-cli/parity.mjs +0 -185
  76. package/examples/marked-cli/vendor/marked/LICENSE +0 -44
  77. package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
  78. package/examples/openai-chat/README.md +0 -148
  79. package/examples/openai-chat/bench.mjs +0 -175
  80. package/examples/openai-chat/main.ts +0 -488
  81. package/examples/react-compiler/README.md +0 -185
  82. package/examples/react-compiler/bench.mjs +0 -181
  83. package/examples/react-compiler/main.ts +0 -324
  84. package/examples/react-compiler/parity.mjs +0 -362
  85. package/examples/react-compiler/run-node.mjs +0 -90
  86. package/examples/react-compiler/vendor/babel/LICENSE +0 -22
  87. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
  88. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
  89. package/examples/react-compiler/vendor/charcodes/package.json +0 -25
  90. package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
  91. package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
  92. package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
  93. package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
  94. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
  95. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
  96. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
  97. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
  98. package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
  99. package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
  100. package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
  101. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
  102. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
  103. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
  104. package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
  105. package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
  106. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
  107. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
  108. package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
  109. package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
  110. package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
  111. package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
  112. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
  113. package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
  114. package/examples/react-compiler/vendor/zod/LICENSE +0 -21
  115. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
  116. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
  117. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
  118. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
  119. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
  120. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
  121. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
  145. package/examples/react-compiler/vendor.mjs +0 -688
  146. package/examples/todo-cli/README.md +0 -69
  147. package/examples/todo-cli/bench.mjs +0 -89
  148. package/examples/todo-cli/main.ts +0 -92
  149. package/examples/yaml-cli/README.md +0 -152
  150. package/examples/yaml-cli/bench.mjs +0 -265
  151. package/examples/yaml-cli/main.ts +0 -251
  152. package/examples/yaml-cli/parity.mjs +0 -156
  153. package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
  154. package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
  155. package/performance/README.md +0 -248
  156. package/performance/any-dynamic.ts +0 -21
  157. package/performance/any-record-view.ts +0 -20
  158. package/performance/arr-for-of.ts +0 -29
  159. package/performance/arr-hof.ts +0 -21
  160. package/performance/arr-push-index.ts +0 -15
  161. package/performance/arr-push-local.ts +0 -39
  162. package/performance/arr-slice-concat.ts +0 -24
  163. package/performance/arr-sort.ts +0 -21
  164. package/performance/async-await.ts +0 -24
  165. package/performance/async-promise-all.ts +0 -38
  166. package/performance/bigint-arith.ts +0 -36
  167. package/performance/buf-encode.ts +0 -29
  168. package/performance/class-accessors.ts +0 -48
  169. package/performance/class-dispatch.ts +0 -52
  170. package/performance/date-format.ts +0 -18
  171. package/performance/events-emit.ts +0 -27
  172. package/performance/exc-throw-rare.ts +0 -25
  173. package/performance/exc-try-catch.ts +0 -26
  174. package/performance/fn-closures.ts +0 -29
  175. package/performance/fn-recursion-tree.ts +0 -31
  176. package/performance/fn-rest-spread.ts +0 -43
  177. package/performance/gen-for-of.ts +0 -46
  178. package/performance/gen-next.ts +0 -32
  179. package/performance/iter-helpers.ts +0 -38
  180. package/performance/json-any.ts +0 -30
  181. package/performance/json-roundtrip.ts +0 -27
  182. package/performance/map-delete.ts +0 -24
  183. package/performance/map-iterate.ts +0 -26
  184. package/performance/map-number-keys.ts +0 -37
  185. package/performance/map-string-keys.ts +0 -22
  186. package/performance/num-arith-loop.ts +0 -14
  187. package/performance/num-bitwise.ts +0 -21
  188. package/performance/num-hash-imul.ts +0 -36
  189. package/performance/num-mod-int.ts +0 -16
  190. package/performance/num-to-string.ts +0 -16
  191. package/performance/obj-alloc.ts +0 -32
  192. package/performance/obj-keys-entries.ts +0 -44
  193. package/performance/obj-optional-chain.ts +0 -42
  194. package/performance/obj-record-dict.ts +0 -24
  195. package/performance/obj-spread-destructure.ts +0 -40
  196. package/performance/regex-exec.ts +0 -29
  197. package/performance/regex-replace-fn.ts +0 -24
  198. package/performance/regex-site.ts +0 -28
  199. package/performance/set-ops.ts +0 -20
  200. package/performance/str-char-scan.ts +0 -35
  201. package/performance/str-concat-plus.ts +0 -18
  202. package/performance/str-concat.ts +0 -24
  203. package/performance/str-methods.ts +0 -24
  204. package/performance/str-short-scan.ts +0 -26
  205. package/performance/str-split-join.ts +0 -23
  206. package/performance/str-switch-compare.ts +0 -50
  207. package/performance/str-template.ts +0 -16
  208. package/performance/str-unicode.ts +0 -25
  209. package/performance/typed-array.ts +0 -30
  210. package/performance/union-switch.ts +0 -57
  211. package/performance/union-typeof.ts +0 -40
  212. package/performance/wasm-call.ts +0 -63
  213. package/tsparser/check.go +0 -158
  214. package/tsparser/go.mod +0 -14
  215. package/tsparser/go.sum +0 -22
  216. package/tsparser/main.go +0 -363
  217. package/tsparser/tsparser.exe +0 -4
@@ -0,0 +1,585 @@
1
+ // node:zlib/iter — iterable compression / decompression transforms for gzip,
2
+ // deflate, brotli, and zstd (both sync and async variants).
3
+ export const zlibIterHelper = `// node:zlib/iter
4
+ type TnZlibIterTransform struct {
5
+ format string
6
+ compress bool
7
+ async bool
8
+ options []interface{}
9
+ }
10
+
11
+ func TnNewZlibIterTransform(format string, compress bool, async bool, options ...interface{}) *TnZlibIterTransform {
12
+ return &TnZlibIterTransform{
13
+ format: format,
14
+ compress: compress,
15
+ async: async,
16
+ options: options,
17
+ }
18
+ }
19
+
20
+ func tnZlibIterMaxOutput(options []interface{}) int {
21
+ if len(options) > 0 && options[0] != nil {
22
+ if v, ok := TnGetValue(options[0], "maxOutputLength").(float64); ok && v >= 0 {
23
+ return int(v)
24
+ }
25
+ }
26
+ return -1
27
+ }
28
+
29
+ func tnZlibIterLevel(options []interface{}) int {
30
+ if len(options) > 0 && options[0] != nil {
31
+ if level, ok := TnGetValue(options[0], "level").(float64); ok {
32
+ return int(level)
33
+ }
34
+ }
35
+ return 4
36
+ }
37
+
38
+ func tnZlibIterSignal(opts []interface{}) interface{} {
39
+ if len(opts) > 0 && opts[0] != nil {
40
+ return TnGetValue(opts[0], "signal")
41
+ }
42
+ return nil
43
+ }
44
+
45
+ func tnZlibIterCheckAbort(signal interface{}) {
46
+ if signal != nil && TnTruthy(TnGetValue(signal, "aborted")) {
47
+ reason := TnGetValue(signal, "reason")
48
+ if reason == nil {
49
+ reason = TnNodeError("AbortError", "ABORT_ERR", "The operation was aborted")
50
+ }
51
+ panic(reason)
52
+ }
53
+ }
54
+
55
+ func tnZlibIterNormalizeBatch(v interface{}) [][]byte {
56
+ if v == nil {
57
+ return nil
58
+ }
59
+ switch x := v.(type) {
60
+ case [][]byte:
61
+ return x
62
+ case []byte:
63
+ return [][]byte{x}
64
+ case string:
65
+ return [][]byte{[]byte(x)}
66
+ case []string:
67
+ out := make([][]byte, len(x))
68
+ for i, s := range x {
69
+ out[i] = []byte(s)
70
+ }
71
+ return out
72
+ case []interface{}:
73
+ out := make([][]byte, 0, len(x))
74
+ for _, el := range x {
75
+ if el == nil {
76
+ continue
77
+ }
78
+ out = append(out, tnZlibInput(el))
79
+ }
80
+ return out
81
+ }
82
+ return [][]byte{tnZlibInput(v)}
83
+ }
84
+
85
+ func tnZlibIterSourceSeq(source interface{}, async bool) iter.Seq[[][]byte] {
86
+ if source == nil {
87
+ return func(yield func([][]byte) bool) {}
88
+ }
89
+ switch s := source.(type) {
90
+ case iter.Seq[[][]byte]:
91
+ return s
92
+ case interface{ tnIterator() iter.Seq[[][]byte] }:
93
+ return s.tnIterator()
94
+ case [][][]byte:
95
+ return func(yield func([][]byte) bool) {
96
+ for _, b := range s {
97
+ if !yield(b) {
98
+ return
99
+ }
100
+ }
101
+ }
102
+ case []interface{}:
103
+ return func(yield func([][]byte) bool) {
104
+ for _, el := range s {
105
+ if el == nil {
106
+ if !yield(nil) {
107
+ return
108
+ }
109
+ continue
110
+ }
111
+ if !yield(tnZlibIterNormalizeBatch(el)) {
112
+ return
113
+ }
114
+ }
115
+ }
116
+ case chan [][]byte:
117
+ if async {
118
+ return func(yield func([][]byte) bool) {
119
+ for {
120
+ TnGenWake(s)
121
+ v, ok := tnRawReceive(s)
122
+ if !ok {
123
+ if reason, rejected := tnRejections.Load(s); rejected {
124
+ panic(reason)
125
+ }
126
+ return
127
+ }
128
+ if !yield(v) {
129
+ return
130
+ }
131
+ }
132
+ }
133
+ }
134
+ return func(yield func([][]byte) bool) {
135
+ g := TnGenLockstep(s)
136
+ first := true
137
+ for {
138
+ if !first {
139
+ TnGenAck(g)
140
+ }
141
+ first = false
142
+ v, ok := <-g
143
+ if !ok {
144
+ TnGenDone(g)
145
+ return
146
+ }
147
+ if !yield(v) {
148
+ TnGenDone(g)
149
+ return
150
+ }
151
+ }
152
+ }
153
+ case chan interface{}:
154
+ if async {
155
+ return func(yield func([][]byte) bool) {
156
+ for {
157
+ TnGenWake(s)
158
+ v, ok := tnRawReceive(s)
159
+ if !ok {
160
+ if reason, rejected := tnRejections.Load(s); rejected {
161
+ panic(reason)
162
+ }
163
+ return
164
+ }
165
+ var batch [][]byte
166
+ if v != nil {
167
+ batch = tnZlibIterNormalizeBatch(v)
168
+ }
169
+ if !yield(batch) {
170
+ return
171
+ }
172
+ }
173
+ }
174
+ }
175
+ return func(yield func([][]byte) bool) {
176
+ g := TnGenLockstep(s)
177
+ first := true
178
+ for {
179
+ if !first {
180
+ TnGenAck(g)
181
+ }
182
+ first = false
183
+ v, ok := <-g
184
+ if !ok {
185
+ TnGenDone(g)
186
+ return
187
+ }
188
+ var batch [][]byte
189
+ if v != nil {
190
+ batch = tnZlibIterNormalizeBatch(v)
191
+ }
192
+ if !yield(batch) {
193
+ TnGenDone(g)
194
+ return
195
+ }
196
+ }
197
+ }
198
+ case interface{ tnIterator() chan interface{} }:
199
+ ch := s.tnIterator()
200
+ return func(yield func([][]byte) bool) {
201
+ for {
202
+ var v interface{}
203
+ var ok bool
204
+ if async {
205
+ v, ok = tnRawReceive(ch)
206
+ } else {
207
+ v, ok = <-ch
208
+ }
209
+ if !ok {
210
+ return
211
+ }
212
+ var batch [][]byte
213
+ if v != nil {
214
+ batch = tnZlibIterNormalizeBatch(v)
215
+ }
216
+ if !yield(batch) {
217
+ return
218
+ }
219
+ }
220
+ }
221
+ }
222
+ rv := reflect.ValueOf(source)
223
+ if rv.Kind() == reflect.Chan {
224
+ return func(yield func([][]byte) bool) {
225
+ for {
226
+ TnGenWake(source)
227
+ v, ok := rv.Recv()
228
+ if !ok {
229
+ return
230
+ }
231
+ val := v.Interface()
232
+ var batch [][]byte
233
+ if val != nil {
234
+ batch = tnZlibIterNormalizeBatch(val)
235
+ }
236
+ if !yield(batch) {
237
+ return
238
+ }
239
+ }
240
+ }
241
+ }
242
+ if rv.Kind() == reflect.Slice {
243
+ return func(yield func([][]byte) bool) {
244
+ for i := 0; i < rv.Len(); i++ {
245
+ val := rv.Index(i).Interface()
246
+ var batch [][]byte
247
+ if val != nil {
248
+ batch = tnZlibIterNormalizeBatch(val)
249
+ }
250
+ if !yield(batch) {
251
+ return
252
+ }
253
+ }
254
+ }
255
+ }
256
+ panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "source is not iterable"))
257
+ }
258
+
259
+ func tnZlibIterCompress(format string, options []interface{}, seq iter.Seq[[][]byte], signal interface{}) iter.Seq[[][]byte] {
260
+ return func(yield func([][]byte) bool) {
261
+ tnZlibIterCheckAbort(signal)
262
+ maxOut := tnZlibIterMaxOutput(options)
263
+ var outBuf bytes.Buffer
264
+ var w io.WriteCloser
265
+ var err error
266
+ switch format {
267
+ case "gzip":
268
+ w, err = gzip.NewWriterLevel(&outBuf, tnZlibIterLevel(options))
269
+ if err != nil {
270
+ panic(TnNodeError("RangeError", "ERR_OUT_OF_RANGE", "The value of \\"options.level\\" is out of range"))
271
+ }
272
+ case "deflate":
273
+ w, err = zlib.NewWriterLevel(&outBuf, tnZlibIterLevel(options))
274
+ if err != nil {
275
+ panic(TnNodeError("RangeError", "ERR_OUT_OF_RANGE", "The value of \\"options.level\\" is out of range"))
276
+ }
277
+ case "brotli":
278
+ w = tnBrotliIterNewWriter(&outBuf, options)
279
+ case "zstd":
280
+ w, err = tnZstdIterNewWriter(&outBuf, options)
281
+ if err != nil {
282
+ panic(TnNodeError("Error", "ZSTD_error_GENERIC", "zstd compression failed"))
283
+ }
284
+ }
285
+ totalOut := 0
286
+ wroteAny := false
287
+ closed := false
288
+ emit := func() bool {
289
+ if outBuf.Len() == 0 {
290
+ return true
291
+ }
292
+ chunk := make([]byte, outBuf.Len())
293
+ copy(chunk, outBuf.Bytes())
294
+ outBuf.Reset()
295
+ totalOut += len(chunk)
296
+ if maxOut >= 0 && totalOut > maxOut {
297
+ panic(TnNodeError("RangeError", "ERR_BUFFER_TOO_LARGE", "Cannot create a Buffer larger than maxOutputLength bytes"))
298
+ }
299
+ return yield([][]byte{chunk})
300
+ }
301
+ defer func() {
302
+ if !closed && w != nil {
303
+ w.Close()
304
+ }
305
+ }()
306
+ for batch := range seq {
307
+ tnZlibIterCheckAbort(signal)
308
+ if batch == nil {
309
+ if !closed {
310
+ closed = true
311
+ if format == "zstd" && !wroteAny {
312
+ w.Close()
313
+ outBuf.Reset()
314
+ outBuf.Write([]byte{0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x00, 0x01, 0x00, 0x00})
315
+ } else {
316
+ w.Close()
317
+ }
318
+ if !emit() {
319
+ return
320
+ }
321
+ }
322
+ continue
323
+ }
324
+ for _, c := range batch {
325
+ if len(c) > 0 {
326
+ wroteAny = true
327
+ w.Write(c)
328
+ }
329
+ }
330
+ if !emit() {
331
+ return
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ func tnZlibIterDecompress(format string, options []interface{}, seq iter.Seq[[][]byte], signal interface{}) iter.Seq[[][]byte] {
338
+ return func(yield func([][]byte) bool) {
339
+ tnZlibIterCheckAbort(signal)
340
+ maxOut := tnZlibIterMaxOutput(options)
341
+ totalOut := 0
342
+ emitChunk := func(chunk []byte) bool {
343
+ totalOut += len(chunk)
344
+ if maxOut >= 0 && totalOut > maxOut {
345
+ panic(TnNodeError("RangeError", "ERR_BUFFER_TOO_LARGE", "Cannot create a Buffer larger than maxOutputLength bytes"))
346
+ }
347
+ return yield([][]byte{chunk})
348
+ }
349
+
350
+ var pr *io.PipeReader
351
+ var pw *io.PipeWriter
352
+ var chunkCh chan []byte
353
+ var writeDoneCh chan error
354
+ var outCh chan []byte
355
+ var cancelCh chan struct{}
356
+ var readerDone chan struct{}
357
+ var writerDone chan struct{}
358
+ var decErr *TnError
359
+ started := false
360
+ inputClosed := false
361
+ readerClosed := false
362
+
363
+ startPipe := func() {
364
+ started = true
365
+ pr, pw = io.Pipe()
366
+ chunkCh = make(chan []byte)
367
+ writeDoneCh = make(chan error, 1)
368
+ outCh = make(chan []byte, 4)
369
+ cancelCh = make(chan struct{})
370
+ readerDone = make(chan struct{})
371
+ writerDone = make(chan struct{})
372
+
373
+ go func() {
374
+ defer close(writerDone)
375
+ for c := range chunkCh {
376
+ _, err := pw.Write(c)
377
+ select {
378
+ case writeDoneCh <- err:
379
+ case <-cancelCh:
380
+ return
381
+ }
382
+ if err != nil {
383
+ return
384
+ }
385
+ }
386
+ pw.Close()
387
+ }()
388
+
389
+ go func() {
390
+ defer close(readerDone)
391
+ defer close(outCh)
392
+ defer pr.Close()
393
+
394
+ var r io.Reader
395
+ var closer io.Closer
396
+ var mapErr func(error) *TnError
397
+
398
+ switch format {
399
+ case "gzip":
400
+ zr, err := gzip.NewReader(pr)
401
+ if err != nil {
402
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
403
+ e := TnNodeError("Error", "Z_BUF_ERROR", "unexpected end of file")
404
+ e.props["errno"] = float64(-5)
405
+ decErr = e
406
+ } else {
407
+ decErr = tnZlibError(err)
408
+ }
409
+ return
410
+ }
411
+ r = zr
412
+ closer = zr
413
+ mapErr = func(err error) *TnError {
414
+ if err == nil || err == io.EOF {
415
+ return nil
416
+ }
417
+ return tnZlibError(err)
418
+ }
419
+ case "deflate":
420
+ zr, err := zlib.NewReader(pr)
421
+ if err != nil {
422
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
423
+ e := TnNodeError("Error", "Z_BUF_ERROR", "unexpected end of file")
424
+ e.props["errno"] = float64(-5)
425
+ decErr = e
426
+ } else {
427
+ decErr = tnZlibError(err)
428
+ }
429
+ return
430
+ }
431
+ r = zr
432
+ closer = zr
433
+ mapErr = func(err error) *TnError {
434
+ if err == nil || err == io.EOF {
435
+ return nil
436
+ }
437
+ return tnZlibError(err)
438
+ }
439
+ case "brotli":
440
+ r, mapErr = tnBrotliIterNewReader(pr)
441
+ case "zstd":
442
+ zr, mErr := tnZstdIterNewReader(pr)
443
+ r = zr
444
+ closer = zr
445
+ mapErr = mErr
446
+ }
447
+ if closer != nil {
448
+ defer closer.Close()
449
+ }
450
+ buf := make([]byte, 16384)
451
+ for {
452
+ n, err := r.Read(buf)
453
+ if n > 0 {
454
+ chunk := make([]byte, n)
455
+ copy(chunk, buf[:n])
456
+ select {
457
+ case outCh <- chunk:
458
+ case <-cancelCh:
459
+ return
460
+ }
461
+ }
462
+ if err != nil {
463
+ if mapped := mapErr(err); mapped != nil {
464
+ decErr = mapped
465
+ }
466
+ return
467
+ }
468
+ }
469
+ }()
470
+ }
471
+
472
+ defer func() {
473
+ if !started {
474
+ return
475
+ }
476
+ close(cancelCh)
477
+ if !inputClosed {
478
+ inputClosed = true
479
+ close(chunkCh)
480
+ }
481
+ pr.Close()
482
+ pw.Close()
483
+ <-readerDone
484
+ <-writerDone
485
+ }()
486
+
487
+ for batch := range seq {
488
+ tnZlibIterCheckAbort(signal)
489
+ if batch == nil {
490
+ if !started {
491
+ e := TnNodeError("Error", "Z_BUF_ERROR", "unexpected end of file")
492
+ e.props["errno"] = float64(-5)
493
+ panic(e)
494
+ }
495
+ if !inputClosed {
496
+ inputClosed = true
497
+ close(chunkCh)
498
+ }
499
+ if !readerClosed {
500
+ for out := range outCh {
501
+ if !emitChunk(out) {
502
+ return
503
+ }
504
+ }
505
+ readerClosed = true
506
+ }
507
+ <-readerDone
508
+ if decErr != nil {
509
+ panic(decErr)
510
+ }
511
+ continue
512
+ }
513
+ for _, c := range batch {
514
+ if len(c) == 0 || readerClosed {
515
+ continue
516
+ }
517
+ if !started {
518
+ startPipe()
519
+ }
520
+ sent := false
521
+ for !sent && !readerClosed {
522
+ select {
523
+ case chunkCh <- c:
524
+ sent = true
525
+ case out, ok := <-outCh:
526
+ if !ok {
527
+ readerClosed = true
528
+ break
529
+ }
530
+ if !emitChunk(out) {
531
+ return
532
+ }
533
+ }
534
+ }
535
+ for sent && !readerClosed {
536
+ select {
537
+ case err := <-writeDoneCh:
538
+ if err != nil {
539
+ for out := range outCh {
540
+ if !emitChunk(out) {
541
+ return
542
+ }
543
+ }
544
+ readerClosed = true
545
+ }
546
+ sent = false
547
+ case out, ok := <-outCh:
548
+ if !ok {
549
+ readerClosed = true
550
+ break
551
+ }
552
+ if !emitChunk(out) {
553
+ return
554
+ }
555
+ }
556
+ }
557
+ if readerClosed {
558
+ <-readerDone
559
+ if decErr != nil {
560
+ panic(decErr)
561
+ }
562
+ }
563
+ }
564
+ }
565
+ }
566
+ }
567
+
568
+ func (t *TnZlibIterTransform) tnTransformSeq(seq iter.Seq[[][]byte], signal interface{}) iter.Seq[[][]byte] {
569
+ if t.compress {
570
+ return tnZlibIterCompress(t.format, t.options, seq, signal)
571
+ }
572
+ return tnZlibIterDecompress(t.format, t.options, seq, signal)
573
+ }
574
+
575
+ func (t *TnZlibIterTransform) transform(source interface{}, opts ...interface{}) iter.Seq[[][]byte] {
576
+ var signal interface{}
577
+ if t.async {
578
+ signal = tnZlibIterSignal(opts)
579
+ }
580
+ return t.tnTransformSeq(tnZlibIterSourceSeq(source, t.async), signal)
581
+ }
582
+
583
+ func (t *TnZlibIterTransform) Get_transform() interface{} {
584
+ return t.transform
585
+ }`;