@comapeo/map-server 1.0.0-pre.0 → 1.0.0-pre.3
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/README.md +5 -6
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/download-request.d.ts.map +1 -1
- package/dist/lib/download-request.js +2 -3
- package/dist/lib/map-share.d.ts +1 -1
- package/dist/lib/map-share.d.ts.map +1 -1
- package/dist/lib/map-share.js +2 -2
- package/dist/lib/secret-stream-fetch.d.ts +1 -1
- package/dist/lib/secret-stream-fetch.d.ts.map +1 -1
- package/dist/lib/secret-stream-fetch.js +2 -1
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +6 -2
- package/dist/routes/downloads.d.ts +1 -1
- package/dist/routes/map-shares.d.ts +1 -1
- package/dist/routes/map-shares.d.ts.map +1 -1
- package/dist/routes/map-shares.js +7 -2
- package/dist/routes/maps.js +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/node_modules/@fastify/busboy/LICENSE +24 -0
- package/node_modules/@fastify/busboy/README.md +270 -0
- package/node_modules/@fastify/busboy/deps/dicer/LICENSE +19 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js +213 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js +100 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js +13 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/dicer.d.ts +164 -0
- package/node_modules/@fastify/busboy/deps/streamsearch/sbmh.js +230 -0
- package/node_modules/@fastify/busboy/lib/main.d.ts +196 -0
- package/node_modules/@fastify/busboy/lib/main.js +85 -0
- package/node_modules/@fastify/busboy/lib/types/multipart.js +306 -0
- package/node_modules/@fastify/busboy/lib/types/urlencoded.js +190 -0
- package/node_modules/@fastify/busboy/lib/utils/Decoder.js +54 -0
- package/node_modules/@fastify/busboy/lib/utils/basename.js +14 -0
- package/node_modules/@fastify/busboy/lib/utils/decodeText.js +114 -0
- package/node_modules/@fastify/busboy/lib/utils/getLimit.js +16 -0
- package/node_modules/@fastify/busboy/lib/utils/parseParams.js +201 -0
- package/node_modules/@fastify/busboy/package.json +81 -0
- package/node_modules/@whatwg-node/fetch/CHANGELOG.md +941 -0
- package/node_modules/@whatwg-node/fetch/README.md +141 -0
- package/node_modules/@whatwg-node/fetch/dist/create-node-ponyfill.js +100 -0
- package/node_modules/@whatwg-node/fetch/dist/esm-ponyfill.js +71 -0
- package/node_modules/@whatwg-node/fetch/dist/global-ponyfill.js +22 -0
- package/node_modules/@whatwg-node/fetch/dist/index.d.ts +73 -0
- package/node_modules/@whatwg-node/fetch/dist/node-ponyfill.js +35 -0
- package/node_modules/@whatwg-node/fetch/dist/shouldSkipPonyfill.js +17 -0
- package/node_modules/@whatwg-node/fetch/package.json +31 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/AbortError.js +19 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Blob.js +291 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Body.js +529 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/CompressionStream.js +34 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/DecompressionStream.js +34 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/File.js +15 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/FormData.js +150 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Headers.js +309 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/IteratorObject.js +134 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/ReadableStream.js +245 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Request.js +128 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Response.js +108 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoder.js +49 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoderStream.js +40 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TransformStream.js +79 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/URL.js +28 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/URLSearchParams.js +4 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/WritableStream.js +115 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetch.js +107 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetchCurl.js +142 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetchNodeHttp.js +152 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/index.js +42 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/utils.js +125 -0
- package/node_modules/@whatwg-node/node-fetch/esm/AbortError.js +15 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Blob.js +279 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Body.js +525 -0
- package/node_modules/@whatwg-node/node-fetch/esm/CompressionStream.js +29 -0
- package/node_modules/@whatwg-node/node-fetch/esm/DecompressionStream.js +29 -0
- package/node_modules/@whatwg-node/node-fetch/esm/File.js +11 -0
- package/node_modules/@whatwg-node/node-fetch/esm/FormData.js +145 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Headers.js +304 -0
- package/node_modules/@whatwg-node/node-fetch/esm/IteratorObject.js +130 -0
- package/node_modules/@whatwg-node/node-fetch/esm/ReadableStream.js +241 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Request.js +124 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Response.js +104 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoder.js +43 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoderStream.js +35 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TransformStream.js +75 -0
- package/node_modules/@whatwg-node/node-fetch/esm/URL.js +24 -0
- package/node_modules/@whatwg-node/node-fetch/esm/URLSearchParams.js +1 -0
- package/node_modules/@whatwg-node/node-fetch/esm/WritableStream.js +111 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetch.js +104 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetchCurl.js +139 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetchNodeHttp.js +148 -0
- package/node_modules/@whatwg-node/node-fetch/esm/index.js +18 -0
- package/node_modules/@whatwg-node/node-fetch/esm/utils.js +110 -0
- package/node_modules/@whatwg-node/node-fetch/package.json +46 -0
- package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.cts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.ts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.cts +63 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.ts +63 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Body.d.cts +54 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Body.d.ts +54 -0
- package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.cts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.ts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.cts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.ts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/File.d.cts +7 -0
- package/node_modules/@whatwg-node/node-fetch/typings/File.d.ts +7 -0
- package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.cts +22 -0
- package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.ts +22 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.cts +26 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.ts +26 -0
- package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.cts +20 -0
- package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.ts +20 -0
- package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.cts +27 -0
- package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.ts +27 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Request.d.cts +38 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Request.d.ts +38 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Response.d.cts +23 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Response.d.ts +23 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.cts +15 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.ts +15 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.cts +14 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.ts +14 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.cts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.ts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URL.d.cts +16 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URL.d.ts +16 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.cts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.ts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.cts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.ts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/index.d.cts +18 -0
- package/node_modules/@whatwg-node/node-fetch/typings/index.d.ts +18 -0
- package/node_modules/@whatwg-node/node-fetch/typings/utils.d.cts +21 -0
- package/node_modules/@whatwg-node/node-fetch/typings/utils.d.ts +21 -0
- package/node_modules/@whatwg-node/server/cjs/index.js +0 -3
- package/node_modules/@whatwg-node/server/esm/index.js +0 -2
- package/node_modules/@whatwg-node/server/package.json +2 -1
- package/node_modules/urlpattern-polyfill/LICENSE +19 -0
- package/node_modules/urlpattern-polyfill/README.md +242 -0
- package/node_modules/urlpattern-polyfill/dist/index.d.ts +9 -0
- package/node_modules/urlpattern-polyfill/dist/types.d.ts +49 -0
- package/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +1 -0
- package/node_modules/urlpattern-polyfill/dist/urlpattern.js +1 -0
- package/node_modules/urlpattern-polyfill/index.cjs +7 -0
- package/node_modules/urlpattern-polyfill/index.js +7 -0
- package/node_modules/urlpattern-polyfill/package.json +149 -0
- package/package.json +19 -10
- package/src/context.ts +1 -1
- package/src/index.ts +3 -2
- package/src/lib/download-request.ts +3 -4
- package/src/lib/map-share.ts +3 -3
- package/src/lib/secret-stream-fetch.ts +3 -2
- package/src/lib/utils.ts +9 -2
- package/src/routes/map-shares.ts +12 -3
- package/src/routes/maps.ts +1 -1
- package/src/types.ts +9 -7
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Type definitions for dicer 0.2
|
|
2
|
+
// Project: https://github.com/mscdex/dicer
|
|
3
|
+
// Definitions by: BendingBender <https://github.com/BendingBender>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
// TypeScript Version: 2.2
|
|
6
|
+
/// <reference types="node" />
|
|
7
|
+
|
|
8
|
+
import stream = require("stream");
|
|
9
|
+
|
|
10
|
+
// tslint:disable:unified-signatures
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A very fast streaming multipart parser for node.js.
|
|
14
|
+
* Dicer is a WritableStream
|
|
15
|
+
*
|
|
16
|
+
* Dicer (special) events:
|
|
17
|
+
* - on('finish', ()) - Emitted when all parts have been parsed and the Dicer instance has been ended.
|
|
18
|
+
* - on('part', (stream: PartStream)) - Emitted when a new part has been found.
|
|
19
|
+
* - on('preamble', (stream: PartStream)) - Emitted for preamble if you should happen to need it (can usually be ignored).
|
|
20
|
+
* - on('trailer', (data: Buffer)) - Emitted when trailing data was found after the terminating boundary (as with the preamble, this can usually be ignored too).
|
|
21
|
+
*/
|
|
22
|
+
export class Dicer extends stream.Writable {
|
|
23
|
+
/**
|
|
24
|
+
* Creates and returns a new Dicer instance with the following valid config settings:
|
|
25
|
+
*
|
|
26
|
+
* @param config The configuration to use
|
|
27
|
+
*/
|
|
28
|
+
constructor(config: Dicer.Config);
|
|
29
|
+
/**
|
|
30
|
+
* Sets the boundary to use for parsing and performs some initialization needed for parsing.
|
|
31
|
+
* You should only need to use this if you set headerFirst to true in the constructor and are parsing the boundary from the preamble header.
|
|
32
|
+
*
|
|
33
|
+
* @param boundary The boundary to use
|
|
34
|
+
*/
|
|
35
|
+
setBoundary(boundary: string): void;
|
|
36
|
+
addListener(event: "finish", listener: () => void): this;
|
|
37
|
+
addListener(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
38
|
+
addListener(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
39
|
+
addListener(event: "trailer", listener: (data: Buffer) => void): this;
|
|
40
|
+
addListener(event: "close", listener: () => void): this;
|
|
41
|
+
addListener(event: "drain", listener: () => void): this;
|
|
42
|
+
addListener(event: "error", listener: (err: Error) => void): this;
|
|
43
|
+
addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
44
|
+
addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
45
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
46
|
+
on(event: "finish", listener: () => void): this;
|
|
47
|
+
on(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
48
|
+
on(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
49
|
+
on(event: "trailer", listener: (data: Buffer) => void): this;
|
|
50
|
+
on(event: "close", listener: () => void): this;
|
|
51
|
+
on(event: "drain", listener: () => void): this;
|
|
52
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
53
|
+
on(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
54
|
+
on(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
55
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
56
|
+
once(event: "finish", listener: () => void): this;
|
|
57
|
+
once(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
58
|
+
once(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
59
|
+
once(event: "trailer", listener: (data: Buffer) => void): this;
|
|
60
|
+
once(event: "close", listener: () => void): this;
|
|
61
|
+
once(event: "drain", listener: () => void): this;
|
|
62
|
+
once(event: "error", listener: (err: Error) => void): this;
|
|
63
|
+
once(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
64
|
+
once(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
65
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
66
|
+
prependListener(event: "finish", listener: () => void): this;
|
|
67
|
+
prependListener(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
68
|
+
prependListener(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
69
|
+
prependListener(event: "trailer", listener: (data: Buffer) => void): this;
|
|
70
|
+
prependListener(event: "close", listener: () => void): this;
|
|
71
|
+
prependListener(event: "drain", listener: () => void): this;
|
|
72
|
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
73
|
+
prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
74
|
+
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
75
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
76
|
+
prependOnceListener(event: "finish", listener: () => void): this;
|
|
77
|
+
prependOnceListener(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
78
|
+
prependOnceListener(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
79
|
+
prependOnceListener(event: "trailer", listener: (data: Buffer) => void): this;
|
|
80
|
+
prependOnceListener(event: "close", listener: () => void): this;
|
|
81
|
+
prependOnceListener(event: "drain", listener: () => void): this;
|
|
82
|
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
83
|
+
prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
84
|
+
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
85
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
86
|
+
removeListener(event: "finish", listener: () => void): this;
|
|
87
|
+
removeListener(event: "part", listener: (stream: Dicer.PartStream) => void): this;
|
|
88
|
+
removeListener(event: "preamble", listener: (stream: Dicer.PartStream) => void): this;
|
|
89
|
+
removeListener(event: "trailer", listener: (data: Buffer) => void): this;
|
|
90
|
+
removeListener(event: "close", listener: () => void): this;
|
|
91
|
+
removeListener(event: "drain", listener: () => void): this;
|
|
92
|
+
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
93
|
+
removeListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
94
|
+
removeListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
95
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare namespace Dicer {
|
|
99
|
+
interface Config {
|
|
100
|
+
/**
|
|
101
|
+
* This is the boundary used to detect the beginning of a new part.
|
|
102
|
+
*/
|
|
103
|
+
boundary?: string | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* If true, preamble header parsing will be performed first.
|
|
106
|
+
*/
|
|
107
|
+
headerFirst?: boolean | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* The maximum number of header key=>value pairs to parse Default: 2000 (same as node's http).
|
|
110
|
+
*/
|
|
111
|
+
maxHeaderPairs?: number | undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* PartStream is a _ReadableStream_
|
|
116
|
+
*
|
|
117
|
+
* PartStream (special) events:
|
|
118
|
+
* - on('header', (header: object)) - An object containing the header for this particular part. Each property value is an array of one or more string values.
|
|
119
|
+
*/
|
|
120
|
+
interface PartStream extends stream.Readable {
|
|
121
|
+
addListener(event: "header", listener: (header: object) => void): this;
|
|
122
|
+
addListener(event: "close", listener: () => void): this;
|
|
123
|
+
addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
124
|
+
addListener(event: "end", listener: () => void): this;
|
|
125
|
+
addListener(event: "readable", listener: () => void): this;
|
|
126
|
+
addListener(event: "error", listener: (err: Error) => void): this;
|
|
127
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
128
|
+
on(event: "header", listener: (header: object) => void): this;
|
|
129
|
+
on(event: "close", listener: () => void): this;
|
|
130
|
+
on(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
131
|
+
on(event: "end", listener: () => void): this;
|
|
132
|
+
on(event: "readable", listener: () => void): this;
|
|
133
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
134
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
135
|
+
once(event: "header", listener: (header: object) => void): this;
|
|
136
|
+
once(event: "close", listener: () => void): this;
|
|
137
|
+
once(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
138
|
+
once(event: "end", listener: () => void): this;
|
|
139
|
+
once(event: "readable", listener: () => void): this;
|
|
140
|
+
once(event: "error", listener: (err: Error) => void): this;
|
|
141
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
142
|
+
prependListener(event: "header", listener: (header: object) => void): this;
|
|
143
|
+
prependListener(event: "close", listener: () => void): this;
|
|
144
|
+
prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
145
|
+
prependListener(event: "end", listener: () => void): this;
|
|
146
|
+
prependListener(event: "readable", listener: () => void): this;
|
|
147
|
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
148
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
149
|
+
prependOnceListener(event: "header", listener: (header: object) => void): this;
|
|
150
|
+
prependOnceListener(event: "close", listener: () => void): this;
|
|
151
|
+
prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
152
|
+
prependOnceListener(event: "end", listener: () => void): this;
|
|
153
|
+
prependOnceListener(event: "readable", listener: () => void): this;
|
|
154
|
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
155
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
156
|
+
removeListener(event: "header", listener: (header: object) => void): this;
|
|
157
|
+
removeListener(event: "close", listener: () => void): this;
|
|
158
|
+
removeListener(event: "data", listener: (chunk: Buffer | string) => void): this;
|
|
159
|
+
removeListener(event: "end", listener: () => void): this;
|
|
160
|
+
removeListener(event: "readable", listener: () => void): this;
|
|
161
|
+
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
162
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright Brian White. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/mscdex/streamsearch
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to
|
|
10
|
+
* deal in the Software without restriction, including without limitation the
|
|
11
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
12
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
|
16
|
+
* all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
* IN THE SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* Based heavily on the Streaming Boyer-Moore-Horspool C++ implementation
|
|
27
|
+
* by Hongli Lai at: https://github.com/FooBarWidget/boyer-moore-horspool
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const { EventEmitter } = require('node:events')
|
|
31
|
+
const { inherits } = require('node:util')
|
|
32
|
+
|
|
33
|
+
function SBMH (needle) {
|
|
34
|
+
if (typeof needle === 'string') {
|
|
35
|
+
needle = Buffer.from(needle)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!Buffer.isBuffer(needle)) {
|
|
39
|
+
throw new TypeError('The needle has to be a String or a Buffer.')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const needleLength = needle.length
|
|
43
|
+
const needleLastCharIndex = needleLength - 1
|
|
44
|
+
|
|
45
|
+
if (needleLength === 0) {
|
|
46
|
+
throw new Error('The needle cannot be an empty String/Buffer.')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (needleLength > 256) {
|
|
50
|
+
throw new Error('The needle cannot have a length bigger than 256.')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.maxMatches = Infinity
|
|
54
|
+
this.matches = 0
|
|
55
|
+
|
|
56
|
+
this._occ = new Uint8Array(256)
|
|
57
|
+
.fill(needleLength) // Initialize occurrence table.
|
|
58
|
+
this._lookbehind_size = 0
|
|
59
|
+
this._needle = needle
|
|
60
|
+
this._bufpos = 0
|
|
61
|
+
|
|
62
|
+
this._lookbehind = Buffer.alloc(needleLastCharIndex)
|
|
63
|
+
|
|
64
|
+
// Populate occurrence table with analysis of the needle,
|
|
65
|
+
// ignoring last letter.
|
|
66
|
+
for (var i = 0; i < needleLastCharIndex; ++i) { // eslint-disable-line no-var
|
|
67
|
+
this._occ[needle[i]] = needleLastCharIndex - i
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
inherits(SBMH, EventEmitter)
|
|
71
|
+
|
|
72
|
+
SBMH.prototype.reset = function () {
|
|
73
|
+
this._lookbehind_size = 0
|
|
74
|
+
this.matches = 0
|
|
75
|
+
this._bufpos = 0
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
SBMH.prototype.push = function (chunk, pos) {
|
|
79
|
+
if (!Buffer.isBuffer(chunk)) {
|
|
80
|
+
chunk = Buffer.from(chunk, 'binary')
|
|
81
|
+
}
|
|
82
|
+
const chlen = chunk.length
|
|
83
|
+
this._bufpos = pos || 0
|
|
84
|
+
let r
|
|
85
|
+
while (r !== chlen && this.matches < this.maxMatches) { r = this._sbmh_feed(chunk) }
|
|
86
|
+
return r
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
SBMH.prototype._sbmh_feed = function (data) {
|
|
90
|
+
const len = data.length
|
|
91
|
+
const needle = this._needle
|
|
92
|
+
const needleLength = needle.length
|
|
93
|
+
const needleLastCharIndex = needleLength - 1
|
|
94
|
+
const needleLastChar = needle[needleLastCharIndex]
|
|
95
|
+
|
|
96
|
+
// Positive: points to a position in `data`
|
|
97
|
+
// pos == 3 points to data[3]
|
|
98
|
+
// Negative: points to a position in the lookbehind buffer
|
|
99
|
+
// pos == -2 points to lookbehind[lookbehind_size - 2]
|
|
100
|
+
let pos = -this._lookbehind_size
|
|
101
|
+
let ch
|
|
102
|
+
|
|
103
|
+
if (pos < 0) {
|
|
104
|
+
// Lookbehind buffer is not empty. Perform Boyer-Moore-Horspool
|
|
105
|
+
// search with character lookup code that considers both the
|
|
106
|
+
// lookbehind buffer and the current round's haystack data.
|
|
107
|
+
//
|
|
108
|
+
// Loop until
|
|
109
|
+
// there is a match.
|
|
110
|
+
// or until
|
|
111
|
+
// we've moved past the position that requires the
|
|
112
|
+
// lookbehind buffer. In this case we switch to the
|
|
113
|
+
// optimized loop.
|
|
114
|
+
// or until
|
|
115
|
+
// the character to look at lies outside the haystack.
|
|
116
|
+
while (pos < 0 && pos <= len - needleLength) {
|
|
117
|
+
ch = data[pos + needleLastCharIndex]
|
|
118
|
+
|
|
119
|
+
if (
|
|
120
|
+
ch === needleLastChar &&
|
|
121
|
+
this._sbmh_memcmp(data, pos, needleLastCharIndex)
|
|
122
|
+
) {
|
|
123
|
+
this._lookbehind_size = 0
|
|
124
|
+
++this.matches
|
|
125
|
+
this.emit('info', true)
|
|
126
|
+
return (this._bufpos = pos + needleLength)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
pos += this._occ[ch]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// No match.
|
|
133
|
+
|
|
134
|
+
while (pos < 0 && !this._sbmh_memcmp(data, pos, len - pos)) {
|
|
135
|
+
// There's too few data for Boyer-Moore-Horspool to run,
|
|
136
|
+
// so let's use a different algorithm to skip as much as
|
|
137
|
+
// we can.
|
|
138
|
+
// Forward pos until
|
|
139
|
+
// the trailing part of lookbehind + data
|
|
140
|
+
// looks like the beginning of the needle
|
|
141
|
+
// or until
|
|
142
|
+
// pos == 0
|
|
143
|
+
++pos
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (pos >= 0) {
|
|
147
|
+
// Discard lookbehind buffer.
|
|
148
|
+
this.emit('info', false, this._lookbehind, 0, this._lookbehind_size)
|
|
149
|
+
this._lookbehind_size = 0
|
|
150
|
+
} else {
|
|
151
|
+
// Cut off part of the lookbehind buffer that has
|
|
152
|
+
// been processed and append the entire haystack
|
|
153
|
+
// into it.
|
|
154
|
+
const bytesToCutOff = this._lookbehind_size + pos
|
|
155
|
+
if (bytesToCutOff > 0) {
|
|
156
|
+
// The cut off data is guaranteed not to contain the needle.
|
|
157
|
+
this.emit('info', false, this._lookbehind, 0, bytesToCutOff)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._lookbehind_size -= bytesToCutOff
|
|
161
|
+
this._lookbehind.copy(this._lookbehind, 0, bytesToCutOff, this._lookbehind_size)
|
|
162
|
+
|
|
163
|
+
data.copy(this._lookbehind, this._lookbehind_size)
|
|
164
|
+
this._lookbehind_size += len
|
|
165
|
+
|
|
166
|
+
this._bufpos = len
|
|
167
|
+
return len
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Lookbehind buffer is now empty. We only need to check if the
|
|
172
|
+
// needle is in the haystack.
|
|
173
|
+
pos = data.indexOf(needle, pos + this._bufpos)
|
|
174
|
+
|
|
175
|
+
if (pos !== -1) {
|
|
176
|
+
++this.matches
|
|
177
|
+
if (pos === 0) { this.emit('info', true) } else { this.emit('info', true, data, this._bufpos, pos) }
|
|
178
|
+
return (this._bufpos = pos + needleLength)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
pos = len - needleLastCharIndex
|
|
182
|
+
if (pos < 0) {
|
|
183
|
+
pos = 0
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// There was no match. If there's trailing haystack data that we cannot
|
|
187
|
+
// match yet using the Boyer-Moore-Horspool algorithm (because the trailing
|
|
188
|
+
// data is less than the needle size) then match using a modified
|
|
189
|
+
// algorithm that starts matching from the beginning instead of the end.
|
|
190
|
+
// Whatever trailing data is left after running this algorithm is added to
|
|
191
|
+
// the lookbehind buffer.
|
|
192
|
+
while (
|
|
193
|
+
pos !== len &&
|
|
194
|
+
(
|
|
195
|
+
data[pos] !== needle[0] ||
|
|
196
|
+
Buffer.compare(
|
|
197
|
+
data.subarray(pos + 1, len),
|
|
198
|
+
needle.subarray(1, len - pos)
|
|
199
|
+
) !== 0
|
|
200
|
+
)
|
|
201
|
+
) {
|
|
202
|
+
++pos
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (pos !== len) {
|
|
206
|
+
data.copy(this._lookbehind, 0, pos, len)
|
|
207
|
+
this._lookbehind_size = len - pos
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Everything until pos is guaranteed not to contain needle data.
|
|
211
|
+
if (pos !== 0) { this.emit('info', false, data, this._bufpos, pos) }
|
|
212
|
+
|
|
213
|
+
this._bufpos = len
|
|
214
|
+
return len
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
SBMH.prototype._sbmh_lookup_char = function (data, pos) {
|
|
218
|
+
return pos < 0
|
|
219
|
+
? this._lookbehind[this._lookbehind_size + pos]
|
|
220
|
+
: data[pos]
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
SBMH.prototype._sbmh_memcmp = function (data, pos, len) {
|
|
224
|
+
for (var i = 0; i < len; ++i) { // eslint-disable-line no-var
|
|
225
|
+
if (this._sbmh_lookup_char(data, pos + i) !== this._needle[i]) { return false }
|
|
226
|
+
}
|
|
227
|
+
return true
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = SBMH
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Definitions by: Jacob Baskin <https://github.com/jacobbaskin>
|
|
2
|
+
// BendingBender <https://github.com/BendingBender>
|
|
3
|
+
// Igor Savin <https://github.com/kibertoad>
|
|
4
|
+
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
|
|
7
|
+
import * as http from 'node:http';
|
|
8
|
+
import { Readable, Writable } from 'node:stream';
|
|
9
|
+
export { Dicer } from "../deps/dicer/lib/dicer";
|
|
10
|
+
|
|
11
|
+
export const Busboy: BusboyConstructor;
|
|
12
|
+
export default Busboy;
|
|
13
|
+
|
|
14
|
+
export interface BusboyConfig {
|
|
15
|
+
/**
|
|
16
|
+
* These are the HTTP headers of the incoming request, which are used by individual parsers.
|
|
17
|
+
*/
|
|
18
|
+
headers: BusboyHeaders;
|
|
19
|
+
/**
|
|
20
|
+
* `highWaterMark` to use for this Busboy instance.
|
|
21
|
+
* @default WritableStream default.
|
|
22
|
+
*/
|
|
23
|
+
highWaterMark?: number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* highWaterMark to use for file streams.
|
|
26
|
+
* @default ReadableStream default.
|
|
27
|
+
*/
|
|
28
|
+
fileHwm?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Default character set to use when one isn't defined.
|
|
31
|
+
* @default 'utf8'
|
|
32
|
+
*/
|
|
33
|
+
defCharset?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Detect if a Part is a file.
|
|
36
|
+
*
|
|
37
|
+
* By default a file is detected if contentType
|
|
38
|
+
* is application/octet-stream or fileName is not
|
|
39
|
+
* undefined.
|
|
40
|
+
*
|
|
41
|
+
* Modify this to handle e.g. Blobs.
|
|
42
|
+
*/
|
|
43
|
+
isPartAFile?: (fieldName: string | undefined, contentType: string | undefined, fileName: string | undefined) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* If paths in the multipart 'filename' field shall be preserved.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
preservePath?: boolean | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Various limits on incoming data.
|
|
51
|
+
*/
|
|
52
|
+
limits?:
|
|
53
|
+
| {
|
|
54
|
+
/**
|
|
55
|
+
* Max field name size (in bytes)
|
|
56
|
+
* @default 100 bytes
|
|
57
|
+
*/
|
|
58
|
+
fieldNameSize?: number | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Max field value size (in bytes)
|
|
61
|
+
* @default 1MB
|
|
62
|
+
*/
|
|
63
|
+
fieldSize?: number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Max number of non-file fields
|
|
66
|
+
* @default Infinity
|
|
67
|
+
*/
|
|
68
|
+
fields?: number | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* For multipart forms, the max file size (in bytes)
|
|
71
|
+
* @default Infinity
|
|
72
|
+
*/
|
|
73
|
+
fileSize?: number | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* For multipart forms, the max number of file fields
|
|
76
|
+
* @default Infinity
|
|
77
|
+
*/
|
|
78
|
+
files?: number | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* For multipart forms, the max number of parts (fields + files)
|
|
81
|
+
* @default Infinity
|
|
82
|
+
*/
|
|
83
|
+
parts?: number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* For multipart forms, the max number of header key=>value pairs to parse
|
|
86
|
+
* @default 2000
|
|
87
|
+
*/
|
|
88
|
+
headerPairs?: number | undefined;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* For multipart forms, the max size of a header part
|
|
92
|
+
* @default 81920
|
|
93
|
+
*/
|
|
94
|
+
headerSize?: number | undefined;
|
|
95
|
+
}
|
|
96
|
+
| undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type BusboyHeaders = { 'content-type': string } & http.IncomingHttpHeaders;
|
|
100
|
+
|
|
101
|
+
export interface BusboyFileStream extends
|
|
102
|
+
Readable {
|
|
103
|
+
|
|
104
|
+
truncated: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The number of bytes that have been read so far.
|
|
108
|
+
*/
|
|
109
|
+
bytesRead: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface Busboy extends Writable {
|
|
113
|
+
addListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
114
|
+
|
|
115
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
116
|
+
|
|
117
|
+
on<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
118
|
+
|
|
119
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
120
|
+
|
|
121
|
+
once<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
122
|
+
|
|
123
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
124
|
+
|
|
125
|
+
removeListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
126
|
+
|
|
127
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
128
|
+
|
|
129
|
+
off<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
130
|
+
|
|
131
|
+
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
132
|
+
|
|
133
|
+
prependListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
134
|
+
|
|
135
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
136
|
+
|
|
137
|
+
prependOnceListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
|
|
138
|
+
|
|
139
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface BusboyEvents {
|
|
143
|
+
/**
|
|
144
|
+
* Emitted for each new file form field found.
|
|
145
|
+
*
|
|
146
|
+
* * Note: if you listen for this event, you should always handle the `stream` no matter if you care about the
|
|
147
|
+
* file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents),
|
|
148
|
+
* otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any**
|
|
149
|
+
* incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically
|
|
150
|
+
* and safely discarded (these discarded files do still count towards `files` and `parts` limits).
|
|
151
|
+
* * If a configured file size limit was reached, `stream` will both have a boolean property `truncated`
|
|
152
|
+
* (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
|
|
153
|
+
*
|
|
154
|
+
* @param listener.transferEncoding Contains the 'Content-Transfer-Encoding' value for the file stream.
|
|
155
|
+
* @param listener.mimeType Contains the 'Content-Type' value for the file stream.
|
|
156
|
+
*/
|
|
157
|
+
file: (
|
|
158
|
+
fieldname: string,
|
|
159
|
+
stream: BusboyFileStream,
|
|
160
|
+
filename: string,
|
|
161
|
+
transferEncoding: string,
|
|
162
|
+
mimeType: string,
|
|
163
|
+
) => void;
|
|
164
|
+
/**
|
|
165
|
+
* Emitted for each new non-file field found.
|
|
166
|
+
*/
|
|
167
|
+
field: (
|
|
168
|
+
fieldname: string,
|
|
169
|
+
value: string,
|
|
170
|
+
fieldnameTruncated: boolean,
|
|
171
|
+
valueTruncated: boolean,
|
|
172
|
+
transferEncoding: string,
|
|
173
|
+
mimeType: string,
|
|
174
|
+
) => void;
|
|
175
|
+
finish: () => void;
|
|
176
|
+
/**
|
|
177
|
+
* Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.
|
|
178
|
+
*/
|
|
179
|
+
partsLimit: () => void;
|
|
180
|
+
/**
|
|
181
|
+
* Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
|
|
182
|
+
*/
|
|
183
|
+
filesLimit: () => void;
|
|
184
|
+
/**
|
|
185
|
+
* Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.
|
|
186
|
+
*/
|
|
187
|
+
fieldsLimit: () => void;
|
|
188
|
+
error: (error: unknown) => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface BusboyConstructor {
|
|
192
|
+
(options: BusboyConfig): Busboy;
|
|
193
|
+
|
|
194
|
+
new(options: BusboyConfig): Busboy;
|
|
195
|
+
}
|
|
196
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const WritableStream = require('node:stream').Writable
|
|
4
|
+
const { inherits } = require('node:util')
|
|
5
|
+
const Dicer = require('../deps/dicer/lib/Dicer')
|
|
6
|
+
|
|
7
|
+
const MultipartParser = require('./types/multipart')
|
|
8
|
+
const UrlencodedParser = require('./types/urlencoded')
|
|
9
|
+
const parseParams = require('./utils/parseParams')
|
|
10
|
+
|
|
11
|
+
function Busboy (opts) {
|
|
12
|
+
if (!(this instanceof Busboy)) { return new Busboy(opts) }
|
|
13
|
+
|
|
14
|
+
if (typeof opts !== 'object') {
|
|
15
|
+
throw new TypeError('Busboy expected an options-Object.')
|
|
16
|
+
}
|
|
17
|
+
if (typeof opts.headers !== 'object') {
|
|
18
|
+
throw new TypeError('Busboy expected an options-Object with headers-attribute.')
|
|
19
|
+
}
|
|
20
|
+
if (typeof opts.headers['content-type'] !== 'string') {
|
|
21
|
+
throw new TypeError('Missing Content-Type-header.')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
headers,
|
|
26
|
+
...streamOptions
|
|
27
|
+
} = opts
|
|
28
|
+
|
|
29
|
+
this.opts = {
|
|
30
|
+
autoDestroy: false,
|
|
31
|
+
...streamOptions
|
|
32
|
+
}
|
|
33
|
+
WritableStream.call(this, this.opts)
|
|
34
|
+
|
|
35
|
+
this._done = false
|
|
36
|
+
this._parser = this.getParserByHeaders(headers)
|
|
37
|
+
this._finished = false
|
|
38
|
+
}
|
|
39
|
+
inherits(Busboy, WritableStream)
|
|
40
|
+
|
|
41
|
+
Busboy.prototype.emit = function (ev) {
|
|
42
|
+
if (ev === 'finish') {
|
|
43
|
+
if (!this._done) {
|
|
44
|
+
this._parser?.end()
|
|
45
|
+
return
|
|
46
|
+
} else if (this._finished) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
this._finished = true
|
|
50
|
+
}
|
|
51
|
+
WritableStream.prototype.emit.apply(this, arguments)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Busboy.prototype.getParserByHeaders = function (headers) {
|
|
55
|
+
const parsed = parseParams(headers['content-type'])
|
|
56
|
+
|
|
57
|
+
const cfg = {
|
|
58
|
+
defCharset: this.opts.defCharset,
|
|
59
|
+
fileHwm: this.opts.fileHwm,
|
|
60
|
+
headers,
|
|
61
|
+
highWaterMark: this.opts.highWaterMark,
|
|
62
|
+
isPartAFile: this.opts.isPartAFile,
|
|
63
|
+
limits: this.opts.limits,
|
|
64
|
+
parsedConType: parsed,
|
|
65
|
+
preservePath: this.opts.preservePath
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (MultipartParser.detect.test(parsed[0])) {
|
|
69
|
+
return new MultipartParser(this, cfg)
|
|
70
|
+
}
|
|
71
|
+
if (UrlencodedParser.detect.test(parsed[0])) {
|
|
72
|
+
return new UrlencodedParser(this, cfg)
|
|
73
|
+
}
|
|
74
|
+
throw new Error('Unsupported Content-Type.')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Busboy.prototype._write = function (chunk, encoding, cb) {
|
|
78
|
+
this._parser.write(chunk, cb)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = Busboy
|
|
82
|
+
module.exports.default = Busboy
|
|
83
|
+
module.exports.Busboy = Busboy
|
|
84
|
+
|
|
85
|
+
module.exports.Dicer = Dicer
|