deepv-code 1.0.182 → 1.0.183

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 (193) hide show
  1. package/bundle/dvcode.js +635 -635
  2. package/package.json +1 -1
  3. package/bundle/assets/help/README.md +0 -113
  4. package/bundle/assets/sounds/README.md +0 -74
  5. package/bundle/node_modules/undici/LICENSE +0 -21
  6. package/bundle/node_modules/undici/README.md +0 -472
  7. package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
  8. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
  9. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
  10. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
  11. package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
  12. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
  13. package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
  14. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
  15. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
  16. package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
  17. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
  18. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
  19. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
  20. package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
  21. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
  22. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
  23. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
  24. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
  25. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
  26. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
  27. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
  28. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
  29. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
  30. package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
  31. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
  32. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
  33. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
  34. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
  35. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
  36. package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
  37. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
  38. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
  39. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
  40. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
  41. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
  42. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
  43. package/bundle/node_modules/undici/index-fetch.js +0 -35
  44. package/bundle/node_modules/undici/index.d.ts +0 -3
  45. package/bundle/node_modules/undici/index.js +0 -183
  46. package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
  47. package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
  48. package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
  49. package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
  50. package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
  51. package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
  52. package/bundle/node_modules/undici/lib/api/index.js +0 -7
  53. package/bundle/node_modules/undici/lib/api/readable.js +0 -558
  54. package/bundle/node_modules/undici/lib/api/util.js +0 -95
  55. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
  56. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
  57. package/bundle/node_modules/undici/lib/core/connect.js +0 -164
  58. package/bundle/node_modules/undici/lib/core/constants.js +0 -143
  59. package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
  60. package/bundle/node_modules/undici/lib/core/errors.js +0 -244
  61. package/bundle/node_modules/undici/lib/core/request.js +0 -397
  62. package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
  63. package/bundle/node_modules/undici/lib/core/tree.js +0 -160
  64. package/bundle/node_modules/undici/lib/core/util.js +0 -988
  65. package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
  66. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
  67. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
  68. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
  69. package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
  70. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
  71. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
  72. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
  73. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
  74. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
  75. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
  76. package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
  77. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
  78. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
  79. package/bundle/node_modules/undici/lib/global.js +0 -32
  80. package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
  81. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
  82. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
  83. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
  84. package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
  85. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
  86. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
  87. package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
  88. package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
  89. package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
  90. package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
  91. package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
  92. package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
  93. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  94. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
  95. package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
  96. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
  97. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
  98. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
  99. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
  100. package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
  101. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
  102. package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
  103. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
  104. package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
  105. package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
  106. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
  107. package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
  108. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
  109. package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
  110. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
  111. package/bundle/node_modules/undici/lib/util/cache.js +0 -368
  112. package/bundle/node_modules/undici/lib/util/date.js +0 -259
  113. package/bundle/node_modules/undici/lib/util/stats.js +0 -32
  114. package/bundle/node_modules/undici/lib/util/timers.js +0 -423
  115. package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
  116. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
  117. package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
  118. package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
  119. package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
  120. package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
  121. package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
  122. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
  123. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
  124. package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
  125. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
  126. package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
  127. package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
  128. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
  129. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
  130. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
  131. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
  132. package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
  133. package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
  134. package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
  135. package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
  136. package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
  137. package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
  138. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
  139. package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
  140. package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
  141. package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
  142. package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
  143. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
  144. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
  145. package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
  146. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
  147. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
  148. package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
  149. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
  150. package/bundle/node_modules/undici/package.json +0 -149
  151. package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
  152. package/bundle/node_modules/undici/types/README.md +0 -6
  153. package/bundle/node_modules/undici/types/agent.d.ts +0 -35
  154. package/bundle/node_modules/undici/types/api.d.ts +0 -43
  155. package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
  156. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
  157. package/bundle/node_modules/undici/types/cache.d.ts +0 -36
  158. package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
  159. package/bundle/node_modules/undici/types/client.d.ts +0 -110
  160. package/bundle/node_modules/undici/types/connector.d.ts +0 -34
  161. package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
  162. package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
  163. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
  164. package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
  165. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
  166. package/bundle/node_modules/undici/types/errors.d.ts +0 -171
  167. package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
  168. package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
  169. package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
  170. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
  171. package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
  172. package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
  173. package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
  174. package/bundle/node_modules/undici/types/header.d.ts +0 -160
  175. package/bundle/node_modules/undici/types/index.d.ts +0 -75
  176. package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
  177. package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
  178. package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
  179. package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
  180. package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
  181. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
  182. package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
  183. package/bundle/node_modules/undici/types/patch.d.ts +0 -29
  184. package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
  185. package/bundle/node_modules/undici/types/pool.d.ts +0 -41
  186. package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
  187. package/bundle/node_modules/undici/types/readable.d.ts +0 -68
  188. package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
  189. package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
  190. package/bundle/node_modules/undici/types/util.d.ts +0 -18
  191. package/bundle/node_modules/undici/types/utility.d.ts +0 -7
  192. package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
  193. package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
@@ -1,46 +0,0 @@
1
- 'use strict'
2
-
3
- const { kConnected, kSize } = require('../../core/symbols')
4
-
5
- class CompatWeakRef {
6
- constructor (value) {
7
- this.value = value
8
- }
9
-
10
- deref () {
11
- return this.value[kConnected] === 0 && this.value[kSize] === 0
12
- ? undefined
13
- : this.value
14
- }
15
- }
16
-
17
- class CompatFinalizer {
18
- constructor (finalizer) {
19
- this.finalizer = finalizer
20
- }
21
-
22
- register (dispatcher, key) {
23
- if (dispatcher.on) {
24
- dispatcher.on('disconnect', () => {
25
- if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
26
- this.finalizer(key)
27
- }
28
- })
29
- }
30
- }
31
-
32
- unregister (key) {}
33
- }
34
-
35
- module.exports = function () {
36
- // FIXME: remove workaround when the Node bug is backported to v18
37
- // https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
38
- if (process.env.NODE_V8_COVERAGE && process.version.startsWith('v18')) {
39
- process._rawDebug('Using compatibility WeakRef and FinalizationRegistry')
40
- return {
41
- WeakRef: CompatWeakRef,
42
- FinalizationRegistry: CompatFinalizer
43
- }
44
- }
45
- return { WeakRef, FinalizationRegistry }
46
- }
@@ -1,501 +0,0 @@
1
- 'use strict'
2
-
3
- const { isUSVString, bufferToLowerCasedHeaderName } = require('../../core/util')
4
- const { utf8DecodeBytes } = require('./util')
5
- const { HTTP_TOKEN_CODEPOINTS, isomorphicDecode } = require('./data-url')
6
- const { makeEntry } = require('./formdata')
7
- const { webidl } = require('./webidl')
8
- const assert = require('node:assert')
9
- const { File: NodeFile } = require('node:buffer')
10
-
11
- const File = globalThis.File ?? NodeFile
12
-
13
- const formDataNameBuffer = Buffer.from('form-data; name="')
14
- const filenameBuffer = Buffer.from('filename')
15
- const dd = Buffer.from('--')
16
- const ddcrlf = Buffer.from('--\r\n')
17
-
18
- /**
19
- * @param {string} chars
20
- */
21
- function isAsciiString (chars) {
22
- for (let i = 0; i < chars.length; ++i) {
23
- if ((chars.charCodeAt(i) & ~0x7F) !== 0) {
24
- return false
25
- }
26
- }
27
- return true
28
- }
29
-
30
- /**
31
- * @see https://andreubotella.github.io/multipart-form-data/#multipart-form-data-boundary
32
- * @param {string} boundary
33
- */
34
- function validateBoundary (boundary) {
35
- const length = boundary.length
36
-
37
- // - its length is greater or equal to 27 and lesser or equal to 70, and
38
- if (length < 27 || length > 70) {
39
- return false
40
- }
41
-
42
- // - it is composed by bytes in the ranges 0x30 to 0x39, 0x41 to 0x5A, or
43
- // 0x61 to 0x7A, inclusive (ASCII alphanumeric), or which are 0x27 ('),
44
- // 0x2D (-) or 0x5F (_).
45
- for (let i = 0; i < length; ++i) {
46
- const cp = boundary.charCodeAt(i)
47
-
48
- if (!(
49
- (cp >= 0x30 && cp <= 0x39) ||
50
- (cp >= 0x41 && cp <= 0x5a) ||
51
- (cp >= 0x61 && cp <= 0x7a) ||
52
- cp === 0x27 ||
53
- cp === 0x2d ||
54
- cp === 0x5f
55
- )) {
56
- return false
57
- }
58
- }
59
-
60
- return true
61
- }
62
-
63
- /**
64
- * @see https://andreubotella.github.io/multipart-form-data/#multipart-form-data-parser
65
- * @param {Buffer} input
66
- * @param {ReturnType<import('./data-url')['parseMIMEType']>} mimeType
67
- */
68
- function multipartFormDataParser (input, mimeType) {
69
- // 1. Assert: mimeType’s essence is "multipart/form-data".
70
- assert(mimeType !== 'failure' && mimeType.essence === 'multipart/form-data')
71
-
72
- const boundaryString = mimeType.parameters.get('boundary')
73
-
74
- // 2. If mimeType’s parameters["boundary"] does not exist, return failure.
75
- // Otherwise, let boundary be the result of UTF-8 decoding mimeType’s
76
- // parameters["boundary"].
77
- if (boundaryString === undefined) {
78
- throw parsingError('missing boundary in content-type header')
79
- }
80
-
81
- const boundary = Buffer.from(`--${boundaryString}`, 'utf8')
82
-
83
- // 3. Let entry list be an empty entry list.
84
- const entryList = []
85
-
86
- // 4. Let position be a pointer to a byte in input, initially pointing at
87
- // the first byte.
88
- const position = { position: 0 }
89
-
90
- // Note: undici addition, allows leading and trailing CRLFs.
91
- while (input[position.position] === 0x0d && input[position.position + 1] === 0x0a) {
92
- position.position += 2
93
- }
94
-
95
- let trailing = input.length
96
-
97
- while (input[trailing - 1] === 0x0a && input[trailing - 2] === 0x0d) {
98
- trailing -= 2
99
- }
100
-
101
- if (trailing !== input.length) {
102
- input = input.subarray(0, trailing)
103
- }
104
-
105
- // 5. While true:
106
- while (true) {
107
- // 5.1. If position points to a sequence of bytes starting with 0x2D 0x2D
108
- // (`--`) followed by boundary, advance position by 2 + the length of
109
- // boundary. Otherwise, return failure.
110
- // Note: boundary is padded with 2 dashes already, no need to add 2.
111
- if (input.subarray(position.position, position.position + boundary.length).equals(boundary)) {
112
- position.position += boundary.length
113
- } else {
114
- throw parsingError('expected a value starting with -- and the boundary')
115
- }
116
-
117
- // 5.2. If position points to the sequence of bytes 0x2D 0x2D 0x0D 0x0A
118
- // (`--` followed by CR LF) followed by the end of input, return entry list.
119
- // Note: a body does NOT need to end with CRLF. It can end with --.
120
- if (
121
- (position.position === input.length - 2 && bufferStartsWith(input, dd, position)) ||
122
- (position.position === input.length - 4 && bufferStartsWith(input, ddcrlf, position))
123
- ) {
124
- return entryList
125
- }
126
-
127
- // 5.3. If position does not point to a sequence of bytes starting with 0x0D
128
- // 0x0A (CR LF), return failure.
129
- if (input[position.position] !== 0x0d || input[position.position + 1] !== 0x0a) {
130
- throw parsingError('expected CRLF')
131
- }
132
-
133
- // 5.4. Advance position by 2. (This skips past the newline.)
134
- position.position += 2
135
-
136
- // 5.5. Let name, filename and contentType be the result of parsing
137
- // multipart/form-data headers on input and position, if the result
138
- // is not failure. Otherwise, return failure.
139
- const result = parseMultipartFormDataHeaders(input, position)
140
-
141
- let { name, filename, contentType, encoding } = result
142
-
143
- // 5.6. Advance position by 2. (This skips past the empty line that marks
144
- // the end of the headers.)
145
- position.position += 2
146
-
147
- // 5.7. Let body be the empty byte sequence.
148
- let body
149
-
150
- // 5.8. Body loop: While position is not past the end of input:
151
- // TODO: the steps here are completely wrong
152
- {
153
- const boundaryIndex = input.indexOf(boundary.subarray(2), position.position)
154
-
155
- if (boundaryIndex === -1) {
156
- throw parsingError('expected boundary after body')
157
- }
158
-
159
- body = input.subarray(position.position, boundaryIndex - 4)
160
-
161
- position.position += body.length
162
-
163
- // Note: position must be advanced by the body's length before being
164
- // decoded, otherwise the parsing will fail.
165
- if (encoding === 'base64') {
166
- body = Buffer.from(body.toString(), 'base64')
167
- }
168
- }
169
-
170
- // 5.9. If position does not point to a sequence of bytes starting with
171
- // 0x0D 0x0A (CR LF), return failure. Otherwise, advance position by 2.
172
- if (input[position.position] !== 0x0d || input[position.position + 1] !== 0x0a) {
173
- throw parsingError('expected CRLF')
174
- } else {
175
- position.position += 2
176
- }
177
-
178
- // 5.10. If filename is not null:
179
- let value
180
-
181
- if (filename !== null) {
182
- // 5.10.1. If contentType is null, set contentType to "text/plain".
183
- contentType ??= 'text/plain'
184
-
185
- // 5.10.2. If contentType is not an ASCII string, set contentType to the empty string.
186
-
187
- // Note: `buffer.isAscii` can be used at zero-cost, but converting a string to a buffer is a high overhead.
188
- // Content-Type is a relatively small string, so it is faster to use `String#charCodeAt`.
189
- if (!isAsciiString(contentType)) {
190
- contentType = ''
191
- }
192
-
193
- // 5.10.3. Let value be a new File object with name filename, type contentType, and body body.
194
- value = new File([body], filename, { type: contentType })
195
- } else {
196
- // 5.11. Otherwise:
197
-
198
- // 5.11.1. Let value be the UTF-8 decoding without BOM of body.
199
- value = utf8DecodeBytes(Buffer.from(body))
200
- }
201
-
202
- // 5.12. Assert: name is a scalar value string and value is either a scalar value string or a File object.
203
- assert(isUSVString(name))
204
- assert((typeof value === 'string' && isUSVString(value)) || webidl.is.File(value))
205
-
206
- // 5.13. Create an entry with name and value, and append it to entry list.
207
- entryList.push(makeEntry(name, value, filename))
208
- }
209
- }
210
-
211
- /**
212
- * @see https://andreubotella.github.io/multipart-form-data/#parse-multipart-form-data-headers
213
- * @param {Buffer} input
214
- * @param {{ position: number }} position
215
- */
216
- function parseMultipartFormDataHeaders (input, position) {
217
- // 1. Let name, filename and contentType be null.
218
- let name = null
219
- let filename = null
220
- let contentType = null
221
- let encoding = null
222
-
223
- // 2. While true:
224
- while (true) {
225
- // 2.1. If position points to a sequence of bytes starting with 0x0D 0x0A (CR LF):
226
- if (input[position.position] === 0x0d && input[position.position + 1] === 0x0a) {
227
- // 2.1.1. If name is null, return failure.
228
- if (name === null) {
229
- throw parsingError('header name is null')
230
- }
231
-
232
- // 2.1.2. Return name, filename and contentType.
233
- return { name, filename, contentType, encoding }
234
- }
235
-
236
- // 2.2. Let header name be the result of collecting a sequence of bytes that are
237
- // not 0x0A (LF), 0x0D (CR) or 0x3A (:), given position.
238
- let headerName = collectASequenceOfBytes(
239
- (char) => char !== 0x0a && char !== 0x0d && char !== 0x3a,
240
- input,
241
- position
242
- )
243
-
244
- // 2.3. Remove any HTTP tab or space bytes from the start or end of header name.
245
- headerName = removeChars(headerName, true, true, (char) => char === 0x9 || char === 0x20)
246
-
247
- // 2.4. If header name does not match the field-name token production, return failure.
248
- if (!HTTP_TOKEN_CODEPOINTS.test(headerName.toString())) {
249
- throw parsingError('header name does not match the field-name token production')
250
- }
251
-
252
- // 2.5. If the byte at position is not 0x3A (:), return failure.
253
- if (input[position.position] !== 0x3a) {
254
- throw parsingError('expected :')
255
- }
256
-
257
- // 2.6. Advance position by 1.
258
- position.position++
259
-
260
- // 2.7. Collect a sequence of bytes that are HTTP tab or space bytes given position.
261
- // (Do nothing with those bytes.)
262
- collectASequenceOfBytes(
263
- (char) => char === 0x20 || char === 0x09,
264
- input,
265
- position
266
- )
267
-
268
- // 2.8. Byte-lowercase header name and switch on the result:
269
- switch (bufferToLowerCasedHeaderName(headerName)) {
270
- case 'content-disposition': {
271
- // 1. Set name and filename to null.
272
- name = filename = null
273
-
274
- // 2. If position does not point to a sequence of bytes starting with
275
- // `form-data; name="`, return failure.
276
- if (!bufferStartsWith(input, formDataNameBuffer, position)) {
277
- throw parsingError('expected form-data; name=" for content-disposition header')
278
- }
279
-
280
- // 3. Advance position so it points at the byte after the next 0x22 (")
281
- // byte (the one in the sequence of bytes matched above).
282
- position.position += 17
283
-
284
- // 4. Set name to the result of parsing a multipart/form-data name given
285
- // input and position, if the result is not failure. Otherwise, return
286
- // failure.
287
- name = parseMultipartFormDataName(input, position)
288
-
289
- // 5. If position points to a sequence of bytes starting with `; filename="`:
290
- if (input[position.position] === 0x3b /* ; */ && input[position.position + 1] === 0x20 /* ' ' */) {
291
- const at = { position: position.position + 2 }
292
-
293
- if (bufferStartsWith(input, filenameBuffer, at)) {
294
- if (input[at.position + 8] === 0x2a /* '*' */) {
295
- at.position += 10 // skip past filename*=
296
-
297
- // Remove leading http tab and spaces. See RFC for examples.
298
- // https://datatracker.ietf.org/doc/html/rfc6266#section-5
299
- collectASequenceOfBytes(
300
- (char) => char === 0x20 || char === 0x09,
301
- input,
302
- at
303
- )
304
-
305
- const headerValue = collectASequenceOfBytes(
306
- (char) => char !== 0x20 && char !== 0x0d && char !== 0x0a, // ' ' or CRLF
307
- input,
308
- at
309
- )
310
-
311
- if (
312
- (headerValue[0] !== 0x75 && headerValue[0] !== 0x55) || // u or U
313
- (headerValue[1] !== 0x74 && headerValue[1] !== 0x54) || // t or T
314
- (headerValue[2] !== 0x66 && headerValue[2] !== 0x46) || // f or F
315
- headerValue[3] !== 0x2d || // -
316
- headerValue[4] !== 0x38 // 8
317
- ) {
318
- throw parsingError('unknown encoding, expected utf-8\'\'')
319
- }
320
-
321
- // skip utf-8''
322
- filename = decodeURIComponent(new TextDecoder().decode(headerValue.subarray(7)))
323
-
324
- position.position = at.position
325
- } else {
326
- // 1. Advance position so it points at the byte after the next 0x22 (") byte
327
- // (the one in the sequence of bytes matched above).
328
- position.position += 11
329
-
330
- // Remove leading http tab and spaces. See RFC for examples.
331
- // https://datatracker.ietf.org/doc/html/rfc6266#section-5
332
- collectASequenceOfBytes(
333
- (char) => char === 0x20 || char === 0x09,
334
- input,
335
- position
336
- )
337
-
338
- position.position++ // skip past " after removing whitespace
339
-
340
- // 2. Set filename to the result of parsing a multipart/form-data name given
341
- // input and position, if the result is not failure. Otherwise, return failure.
342
- filename = parseMultipartFormDataName(input, position)
343
- }
344
- }
345
- }
346
-
347
- break
348
- }
349
- case 'content-type': {
350
- // 1. Let header value be the result of collecting a sequence of bytes that are
351
- // not 0x0A (LF) or 0x0D (CR), given position.
352
- let headerValue = collectASequenceOfBytes(
353
- (char) => char !== 0x0a && char !== 0x0d,
354
- input,
355
- position
356
- )
357
-
358
- // 2. Remove any HTTP tab or space bytes from the end of header value.
359
- headerValue = removeChars(headerValue, false, true, (char) => char === 0x9 || char === 0x20)
360
-
361
- // 3. Set contentType to the isomorphic decoding of header value.
362
- contentType = isomorphicDecode(headerValue)
363
-
364
- break
365
- }
366
- case 'content-transfer-encoding': {
367
- let headerValue = collectASequenceOfBytes(
368
- (char) => char !== 0x0a && char !== 0x0d,
369
- input,
370
- position
371
- )
372
-
373
- headerValue = removeChars(headerValue, false, true, (char) => char === 0x9 || char === 0x20)
374
-
375
- encoding = isomorphicDecode(headerValue)
376
-
377
- break
378
- }
379
- default: {
380
- // Collect a sequence of bytes that are not 0x0A (LF) or 0x0D (CR), given position.
381
- // (Do nothing with those bytes.)
382
- collectASequenceOfBytes(
383
- (char) => char !== 0x0a && char !== 0x0d,
384
- input,
385
- position
386
- )
387
- }
388
- }
389
-
390
- // 2.9. If position does not point to a sequence of bytes starting with 0x0D 0x0A
391
- // (CR LF), return failure. Otherwise, advance position by 2 (past the newline).
392
- if (input[position.position] !== 0x0d && input[position.position + 1] !== 0x0a) {
393
- throw parsingError('expected CRLF')
394
- } else {
395
- position.position += 2
396
- }
397
- }
398
- }
399
-
400
- /**
401
- * @see https://andreubotella.github.io/multipart-form-data/#parse-a-multipart-form-data-name
402
- * @param {Buffer} input
403
- * @param {{ position: number }} position
404
- */
405
- function parseMultipartFormDataName (input, position) {
406
- // 1. Assert: The byte at (position - 1) is 0x22 (").
407
- assert(input[position.position - 1] === 0x22)
408
-
409
- // 2. Let name be the result of collecting a sequence of bytes that are not 0x0A (LF), 0x0D (CR) or 0x22 ("), given position.
410
- /** @type {string | Buffer} */
411
- let name = collectASequenceOfBytes(
412
- (char) => char !== 0x0a && char !== 0x0d && char !== 0x22,
413
- input,
414
- position
415
- )
416
-
417
- // 3. If the byte at position is not 0x22 ("), return failure. Otherwise, advance position by 1.
418
- if (input[position.position] !== 0x22) {
419
- throw parsingError('expected "')
420
- } else {
421
- position.position++
422
- }
423
-
424
- // 4. Replace any occurrence of the following subsequences in name with the given byte:
425
- // - `%0A`: 0x0A (LF)
426
- // - `%0D`: 0x0D (CR)
427
- // - `%22`: 0x22 (")
428
- name = new TextDecoder().decode(name)
429
- .replace(/%0A/ig, '\n')
430
- .replace(/%0D/ig, '\r')
431
- .replace(/%22/g, '"')
432
-
433
- // 5. Return the UTF-8 decoding without BOM of name.
434
- return name
435
- }
436
-
437
- /**
438
- * @param {(char: number) => boolean} condition
439
- * @param {Buffer} input
440
- * @param {{ position: number }} position
441
- */
442
- function collectASequenceOfBytes (condition, input, position) {
443
- let start = position.position
444
-
445
- while (start < input.length && condition(input[start])) {
446
- ++start
447
- }
448
-
449
- return input.subarray(position.position, (position.position = start))
450
- }
451
-
452
- /**
453
- * @param {Buffer} buf
454
- * @param {boolean} leading
455
- * @param {boolean} trailing
456
- * @param {(charCode: number) => boolean} predicate
457
- * @returns {Buffer}
458
- */
459
- function removeChars (buf, leading, trailing, predicate) {
460
- let lead = 0
461
- let trail = buf.length - 1
462
-
463
- if (leading) {
464
- while (lead < buf.length && predicate(buf[lead])) lead++
465
- }
466
-
467
- if (trailing) {
468
- while (trail > 0 && predicate(buf[trail])) trail--
469
- }
470
-
471
- return lead === 0 && trail === buf.length - 1 ? buf : buf.subarray(lead, trail + 1)
472
- }
473
-
474
- /**
475
- * Checks if {@param buffer} starts with {@param start}
476
- * @param {Buffer} buffer
477
- * @param {Buffer} start
478
- * @param {{ position: number }} position
479
- */
480
- function bufferStartsWith (buffer, start, position) {
481
- if (buffer.length < start.length) {
482
- return false
483
- }
484
-
485
- for (let i = 0; i < start.length; i++) {
486
- if (start[i] !== buffer[position.position + i]) {
487
- return false
488
- }
489
- }
490
-
491
- return true
492
- }
493
-
494
- function parsingError (cause) {
495
- return new TypeError('Failed to parse body as FormData.', { cause: new TypeError(cause) })
496
- }
497
-
498
- module.exports = {
499
- multipartFormDataParser,
500
- validateBoundary
501
- }