@comapeo/map-server 1.0.0-pre.0 → 1.0.0-pre.2
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/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 +1 -0
- package/dist/lib/map-share.js +1 -1
- package/dist/routes/maps.js +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.js +2 -2
- 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/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 +18 -8
- package/src/context.ts +1 -1
- package/src/index.ts +2 -0
- package/src/lib/map-share.ts +1 -1
- package/src/routes/maps.ts +1 -1
- package/src/types.ts +2 -2
package/dist/context.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class Context {
|
|
|
20
20
|
maxzoom: number;
|
|
21
21
|
minzoom: number;
|
|
22
22
|
estimatedSizeBytes: number;
|
|
23
|
-
|
|
23
|
+
mapCreatedAt: number;
|
|
24
24
|
}>;
|
|
25
25
|
getReader(mapId: string): Promise<Reader>;
|
|
26
26
|
createMapReadableStream(mapId: string): ReadableStream<Uint8Array>;
|
package/dist/context.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { errors } from './lib/errors.js';
|
|
1
2
|
export type { MapInfo, MapShareState, MapShareStateUpdate, DownloadStateUpdate, } from './types.js';
|
|
2
3
|
export type { DownloadState } from './lib/download-request.js';
|
|
3
4
|
export type { MapShareCreateParams, MapShareDeclineParams, } from './routes/map-shares.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,YAAY,EACX,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EACX,oBAAoB,EACpB,qBAAqB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,MAAM,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,MAAM,GAAG,GAAG,CAAA;IACnC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAA;IAC3B,eAAe,EAAE,MAAM,GAAG,GAAG,CAAA;IAC7B,OAAO,CAAC,EAAE;QACT,SAAS,EAAE,UAAU,CAAA;QACrB,SAAS,EAAE,UAAU,CAAA;KACrB,CAAA;CACD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAOD,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa;kBA+C9B,aAAa;;;;;EA6BjC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,YAAY,EACX,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EACX,oBAAoB,EACpB,qBAAqB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,MAAM,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,MAAM,GAAG,GAAG,CAAA;IACnC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAA;IAC3B,eAAe,EAAE,MAAM,GAAG,GAAG,CAAA;IAC7B,OAAO,CAAC,EAAE;QACT,SAAS,EAAE,UAAU,CAAA;QACrB,SAAS,EAAE,UAAU,CAAA;KACrB,CAAA;CACD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAOD,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa;kBA+C9B,aAAa;;;;;EA6BjC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import z32 from 'z32';
|
|
|
8
8
|
import { Context } from './context.js';
|
|
9
9
|
import { fetchAPI } from './lib/fetch-api.js';
|
|
10
10
|
import { RootRouter } from './routes/root.js';
|
|
11
|
+
export { errors } from './lib/errors.js';
|
|
11
12
|
export function createServer(options) {
|
|
12
13
|
validateOptions(options);
|
|
13
14
|
if (!options.keyPair) {
|
package/dist/lib/map-share.js
CHANGED
|
@@ -16,7 +16,7 @@ export class MapShare extends TypedEventTarget {
|
|
|
16
16
|
shareId,
|
|
17
17
|
mapShareUrls: baseUrls.map((baseUrl) => new URL(`${shareId}`, addTrailingSlash(baseUrl)).href),
|
|
18
18
|
receiverDeviceId,
|
|
19
|
-
|
|
19
|
+
mapShareCreatedAt: Date.now(),
|
|
20
20
|
status: 'pending',
|
|
21
21
|
};
|
|
22
22
|
}
|
package/dist/routes/maps.js
CHANGED
|
@@ -14,7 +14,7 @@ export function MapsRouter({ base = '/' }, ctx) {
|
|
|
14
14
|
router.get(`/:mapId/info`, async (request) => {
|
|
15
15
|
const info = await ctx.getMapInfo(request.params.mapId);
|
|
16
16
|
return {
|
|
17
|
-
created: info.
|
|
17
|
+
created: info.mapCreatedAt,
|
|
18
18
|
size: info.estimatedSizeBytes,
|
|
19
19
|
name: info.mapName,
|
|
20
20
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -38,13 +38,13 @@ declare const MapInfo: T.TObject<{
|
|
|
38
38
|
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
39
39
|
minzoom: T.TNumber;
|
|
40
40
|
maxzoom: T.TNumber;
|
|
41
|
-
|
|
41
|
+
mapCreatedAt: T.TNumber;
|
|
42
42
|
}>;
|
|
43
43
|
declare const MapShareBase: T.TIntersect<[T.TObject<{
|
|
44
44
|
receiverDeviceId: T.TString;
|
|
45
45
|
shareId: T.TString;
|
|
46
46
|
mapShareUrls: T.TArray<T.TString>;
|
|
47
|
-
|
|
47
|
+
mapShareCreatedAt: T.TNumber;
|
|
48
48
|
}>, T.TObject<{
|
|
49
49
|
mapId: T.TString;
|
|
50
50
|
mapName: T.TString;
|
|
@@ -52,13 +52,13 @@ declare const MapShareBase: T.TIntersect<[T.TObject<{
|
|
|
52
52
|
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
53
53
|
minzoom: T.TNumber;
|
|
54
54
|
maxzoom: T.TNumber;
|
|
55
|
-
|
|
55
|
+
mapCreatedAt: T.TNumber;
|
|
56
56
|
}>]>;
|
|
57
57
|
export declare const MapShareState: T.TIntersect<[T.TIntersect<[T.TObject<{
|
|
58
58
|
receiverDeviceId: T.TString;
|
|
59
59
|
shareId: T.TString;
|
|
60
60
|
mapShareUrls: T.TArray<T.TString>;
|
|
61
|
-
|
|
61
|
+
mapShareCreatedAt: T.TNumber;
|
|
62
62
|
}>, T.TObject<{
|
|
63
63
|
mapId: T.TString;
|
|
64
64
|
mapName: T.TString;
|
|
@@ -66,7 +66,7 @@ export declare const MapShareState: T.TIntersect<[T.TIntersect<[T.TObject<{
|
|
|
66
66
|
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
67
67
|
minzoom: T.TNumber;
|
|
68
68
|
maxzoom: T.TNumber;
|
|
69
|
-
|
|
69
|
+
mapCreatedAt: T.TNumber;
|
|
70
70
|
}>]>, T.TUnion<[T.TObject<{
|
|
71
71
|
status: T.TLiteral<"pending">;
|
|
72
72
|
}>, T.TObject<{
|
package/dist/types.js
CHANGED
|
@@ -76,7 +76,7 @@ const MapInfo = T.Object({
|
|
|
76
76
|
})),
|
|
77
77
|
minzoom: T.Number({ description: 'The minimum zoom level of the map data' }),
|
|
78
78
|
maxzoom: T.Number({ description: 'The maximum zoom level of the map data' }),
|
|
79
|
-
|
|
79
|
+
mapCreatedAt: T.Number({
|
|
80
80
|
description: 'Timestamp (ms since epoch) when the map was created',
|
|
81
81
|
}),
|
|
82
82
|
});
|
|
@@ -87,7 +87,7 @@ const MapShareBase = T.Intersect([
|
|
|
87
87
|
}),
|
|
88
88
|
shareId: ShareId,
|
|
89
89
|
mapShareUrls: MapShareUrls,
|
|
90
|
-
|
|
90
|
+
mapShareCreatedAt: T.Number({
|
|
91
91
|
description: 'Timestamp (ms since epoch) when the map share was created',
|
|
92
92
|
}),
|
|
93
93
|
}),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright Brian White. All rights reserved.
|
|
4
|
+
Copyright (c) 2021-present The Fastify team
|
|
5
|
+
|
|
6
|
+
The Fastify team members are listed at https://github.com/fastify/fastify#team.
|
|
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 deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
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 all
|
|
16
|
+
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 FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# busboy
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://github.com/fastify/busboy/actions)
|
|
6
|
+
[](https://standardjs.com/)
|
|
7
|
+
[](https://github.com/fastify/.github/blob/main/SECURITY.md)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@fastify/busboy)
|
|
14
|
+
[](https://www.npmjs.com/package/@fastify/busboy)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
Description
|
|
19
|
+
===========
|
|
20
|
+
|
|
21
|
+
A Node.js module for parsing incoming HTML form data.
|
|
22
|
+
|
|
23
|
+
This is an officially supported fork by [fastify](https://github.com/fastify/) organization of the amazing library [originally created](https://github.com/mscdex/busboy) by Brian White,
|
|
24
|
+
aimed at addressing long-standing issues with it.
|
|
25
|
+
|
|
26
|
+
Benchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):
|
|
27
|
+
|
|
28
|
+
| Library | Version | Mean time in nanoseconds (less is better) |
|
|
29
|
+
|-----------------------|---------|-------------------------------------------|
|
|
30
|
+
| busboy | 0.3.1 | `340114` |
|
|
31
|
+
| @fastify/busboy | 1.0.0 | `270984` |
|
|
32
|
+
|
|
33
|
+
[Changelog](https://github.com/fastify/busboy/blob/main/CHANGELOG.md) since busboy 0.31.
|
|
34
|
+
|
|
35
|
+
Requirements
|
|
36
|
+
============
|
|
37
|
+
|
|
38
|
+
* [Node.js](http://nodejs.org/) 10+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Install
|
|
42
|
+
=======
|
|
43
|
+
|
|
44
|
+
npm i @fastify/busboy
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Examples
|
|
48
|
+
========
|
|
49
|
+
|
|
50
|
+
* Parsing (multipart) with default options:
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
const http = require('node:http');
|
|
54
|
+
const { inspect } = require('node:util');
|
|
55
|
+
const Busboy = require('@fastify/busboy');
|
|
56
|
+
|
|
57
|
+
http.createServer((req, res) => {
|
|
58
|
+
if (req.method === 'POST') {
|
|
59
|
+
const busboy = new Busboy({ headers: req.headers });
|
|
60
|
+
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
|
|
61
|
+
console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);
|
|
62
|
+
file.on('data', data => {
|
|
63
|
+
console.log(`File [${fieldname}] got ${data.length} bytes`);
|
|
64
|
+
});
|
|
65
|
+
file.on('end', () => {
|
|
66
|
+
console.log(`File [${fieldname}] Finished`);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
|
|
70
|
+
console.log(`Field [${fieldname}]: value: ${inspect(val)}`);
|
|
71
|
+
});
|
|
72
|
+
busboy.on('finish', () => {
|
|
73
|
+
console.log('Done parsing form!');
|
|
74
|
+
res.writeHead(303, { Connection: 'close', Location: '/' });
|
|
75
|
+
res.end();
|
|
76
|
+
});
|
|
77
|
+
req.pipe(busboy);
|
|
78
|
+
} else if (req.method === 'GET') {
|
|
79
|
+
res.writeHead(200, { Connection: 'close' });
|
|
80
|
+
res.end(`<html><head></head><body>
|
|
81
|
+
<form method="POST" enctype="multipart/form-data">
|
|
82
|
+
<input type="text" name="textfield"><br>
|
|
83
|
+
<input type="file" name="filefield"><br>
|
|
84
|
+
<input type="submit">
|
|
85
|
+
</form>
|
|
86
|
+
</body></html>`);
|
|
87
|
+
}
|
|
88
|
+
}).listen(8000, () => {
|
|
89
|
+
console.log('Listening for requests');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file:
|
|
93
|
+
//
|
|
94
|
+
// Listening for requests
|
|
95
|
+
// File [filefield]: filename: ryan-speaker.jpg, encoding: binary
|
|
96
|
+
// File [filefield] got 11971 bytes
|
|
97
|
+
// Field [textfield]: value: 'testing! :-)'
|
|
98
|
+
// File [filefield] Finished
|
|
99
|
+
// Done parsing form!
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
* Save all incoming files to disk:
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
const http = require('node:http');
|
|
106
|
+
const path = require('node:path');
|
|
107
|
+
const os = require('node:os');
|
|
108
|
+
const fs = require('node:fs');
|
|
109
|
+
|
|
110
|
+
const Busboy = require('@fastify/busboy');
|
|
111
|
+
|
|
112
|
+
http.createServer(function(req, res) {
|
|
113
|
+
if (req.method === 'POST') {
|
|
114
|
+
const busboy = new Busboy({ headers: req.headers });
|
|
115
|
+
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
|
|
116
|
+
var saveTo = path.join(os.tmpdir(), path.basename(fieldname));
|
|
117
|
+
file.pipe(fs.createWriteStream(saveTo));
|
|
118
|
+
});
|
|
119
|
+
busboy.on('finish', function() {
|
|
120
|
+
res.writeHead(200, { 'Connection': 'close' });
|
|
121
|
+
res.end("That's all folks!");
|
|
122
|
+
});
|
|
123
|
+
return req.pipe(busboy);
|
|
124
|
+
}
|
|
125
|
+
res.writeHead(404);
|
|
126
|
+
res.end();
|
|
127
|
+
}).listen(8000, function() {
|
|
128
|
+
console.log('Listening for requests');
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
* Parsing (urlencoded) with default options:
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const http = require('node:http');
|
|
136
|
+
const { inspect } = require('node:util');
|
|
137
|
+
|
|
138
|
+
const Busboy = require('@fastify/busboy');
|
|
139
|
+
|
|
140
|
+
http.createServer(function(req, res) {
|
|
141
|
+
if (req.method === 'POST') {
|
|
142
|
+
const busboy = new Busboy({ headers: req.headers });
|
|
143
|
+
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
|
|
144
|
+
console.log('File [' + fieldname + ']: filename: ' + filename);
|
|
145
|
+
file.on('data', function(data) {
|
|
146
|
+
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
|
|
147
|
+
});
|
|
148
|
+
file.on('end', function() {
|
|
149
|
+
console.log('File [' + fieldname + '] Finished');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
|
|
153
|
+
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
|
|
154
|
+
});
|
|
155
|
+
busboy.on('finish', function() {
|
|
156
|
+
console.log('Done parsing form!');
|
|
157
|
+
res.writeHead(303, { Connection: 'close', Location: '/' });
|
|
158
|
+
res.end();
|
|
159
|
+
});
|
|
160
|
+
req.pipe(busboy);
|
|
161
|
+
} else if (req.method === 'GET') {
|
|
162
|
+
res.writeHead(200, { Connection: 'close' });
|
|
163
|
+
res.end('<html><head></head><body>\
|
|
164
|
+
<form method="POST">\
|
|
165
|
+
<input type="text" name="textfield"><br />\
|
|
166
|
+
<select name="selectfield">\
|
|
167
|
+
<option value="1">1</option>\
|
|
168
|
+
<option value="10">10</option>\
|
|
169
|
+
<option value="100">100</option>\
|
|
170
|
+
<option value="9001">9001</option>\
|
|
171
|
+
</select><br />\
|
|
172
|
+
<input type="checkbox" name="checkfield">Node.js rules!<br />\
|
|
173
|
+
<input type="submit">\
|
|
174
|
+
</form>\
|
|
175
|
+
</body></html>');
|
|
176
|
+
}
|
|
177
|
+
}).listen(8000, function() {
|
|
178
|
+
console.log('Listening for requests');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Example output:
|
|
182
|
+
//
|
|
183
|
+
// Listening for requests
|
|
184
|
+
// Field [textfield]: value: 'testing! :-)'
|
|
185
|
+
// Field [selectfield]: value: '9001'
|
|
186
|
+
// Field [checkfield]: value: 'on'
|
|
187
|
+
// Done parsing form!
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
API
|
|
192
|
+
===
|
|
193
|
+
|
|
194
|
+
_Busboy_ is a _Writable_ stream
|
|
195
|
+
|
|
196
|
+
Busboy (special) events
|
|
197
|
+
-----------------------
|
|
198
|
+
|
|
199
|
+
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. `mimeType` contains the 'Content-Type' value for the file stream.
|
|
200
|
+
* Note: if you listen for this event, you should always handle the `stream` no matter if you care about the file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any** incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards `files` and `parts` limits).
|
|
201
|
+
* If a configured file size limit was reached, `stream` will both have a boolean property `truncated` (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
|
|
202
|
+
* The property `bytesRead` informs about the number of bytes that have been read so far.
|
|
203
|
+
|
|
204
|
+
* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >fieldnameTruncated, < _boolean_ >valueTruncated, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new non-file field found.
|
|
205
|
+
|
|
206
|
+
* **partsLimit**() - Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.
|
|
207
|
+
|
|
208
|
+
* **filesLimit**() - Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
|
|
209
|
+
|
|
210
|
+
* **fieldsLimit**() - Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
Busboy methods
|
|
214
|
+
--------------
|
|
215
|
+
|
|
216
|
+
* **(constructor)**(< _object_ >config) - Creates and returns a new Busboy instance.
|
|
217
|
+
|
|
218
|
+
* The constructor takes the following valid `config` settings:
|
|
219
|
+
|
|
220
|
+
* **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.
|
|
221
|
+
|
|
222
|
+
* **autoDestroy** - _boolean_ - Whether this stream should automatically call .destroy() on itself after ending. (Default: false).
|
|
223
|
+
|
|
224
|
+
* **highWaterMark** - _integer_ - highWaterMark to use for this Busboy instance (Default: WritableStream default).
|
|
225
|
+
|
|
226
|
+
* **fileHwm** - _integer_ - highWaterMark to use for file streams (Default: ReadableStream default).
|
|
227
|
+
|
|
228
|
+
* **defCharset** - _string_ - Default character set to use when one isn't defined (Default: 'utf8').
|
|
229
|
+
|
|
230
|
+
* **preservePath** - _boolean_ - If paths in the multipart 'filename' field shall be preserved. (Default: false).
|
|
231
|
+
|
|
232
|
+
* **isPartAFile** - __function__ - Use this function to override the default file detection functionality. It has following parameters:
|
|
233
|
+
|
|
234
|
+
* fieldName - __string__ The name of the field.
|
|
235
|
+
|
|
236
|
+
* contentType - __string__ The content-type of the part, e.g. `text/plain`, `image/jpeg`, `application/octet-stream`
|
|
237
|
+
|
|
238
|
+
* fileName - __string__ The name of a file supplied by the part.
|
|
239
|
+
|
|
240
|
+
(Default: `(fieldName, contentType, fileName) => (contentType === 'application/octet-stream' || fileName !== undefined)`)
|
|
241
|
+
|
|
242
|
+
* **limits** - _object_ - Various limits on incoming data. Valid properties are:
|
|
243
|
+
|
|
244
|
+
* **fieldNameSize** - _integer_ - Max field name size (in bytes) (Default: 100 bytes).
|
|
245
|
+
|
|
246
|
+
* **fieldSize** - _integer_ - Max field value size (in bytes) (Default: 1 MiB, which is 1024 x 1024 bytes).
|
|
247
|
+
|
|
248
|
+
* **fields** - _integer_ - Max number of non-file fields (Default: Infinity).
|
|
249
|
+
|
|
250
|
+
* **fileSize** - _integer_ - For multipart forms, the max file size (in bytes) (Default: Infinity).
|
|
251
|
+
|
|
252
|
+
* **files** - _integer_ - For multipart forms, the max number of file fields (Default: Infinity).
|
|
253
|
+
|
|
254
|
+
* **parts** - _integer_ - For multipart forms, the max number of parts (fields + files) (Default: Infinity).
|
|
255
|
+
|
|
256
|
+
* **headerPairs** - _integer_ - For multipart forms, the max number of header key=>value pairs to parse **Default:** 2000
|
|
257
|
+
|
|
258
|
+
* **headerSize** - _integer_ - For multipart forms, the max size of a multipart header **Default:** 81920.
|
|
259
|
+
|
|
260
|
+
* The constructor can throw errors:
|
|
261
|
+
|
|
262
|
+
* **Busboy expected an options-Object.** - Busboy expected an Object as first parameters.
|
|
263
|
+
|
|
264
|
+
* **Busboy expected an options-Object with headers-attribute.** - The first parameter is lacking of a headers-attribute.
|
|
265
|
+
|
|
266
|
+
* **Limit $limit is not a valid number** - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number.
|
|
267
|
+
|
|
268
|
+
* **Unsupported Content-Type.** - The `Content-Type` isn't one Busboy can parse.
|
|
269
|
+
|
|
270
|
+
* **Missing Content-Type-header.** - The provided headers don't include `Content-Type` at all.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright Brian White. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
|
5
|
+
deal in the Software without restriction, including without limitation the
|
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19
|
+
IN THE SOFTWARE.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const WritableStream = require('node:stream').Writable
|
|
4
|
+
const inherits = require('node:util').inherits
|
|
5
|
+
|
|
6
|
+
const StreamSearch = require('../../streamsearch/sbmh')
|
|
7
|
+
|
|
8
|
+
const PartStream = require('./PartStream')
|
|
9
|
+
const HeaderParser = require('./HeaderParser')
|
|
10
|
+
|
|
11
|
+
const DASH = 45
|
|
12
|
+
const B_ONEDASH = Buffer.from('-')
|
|
13
|
+
const B_CRLF = Buffer.from('\r\n')
|
|
14
|
+
const EMPTY_FN = function () {}
|
|
15
|
+
|
|
16
|
+
function Dicer (cfg) {
|
|
17
|
+
if (!(this instanceof Dicer)) { return new Dicer(cfg) }
|
|
18
|
+
WritableStream.call(this, cfg)
|
|
19
|
+
|
|
20
|
+
if (!cfg || (!cfg.headerFirst && typeof cfg.boundary !== 'string')) { throw new TypeError('Boundary required') }
|
|
21
|
+
|
|
22
|
+
if (typeof cfg.boundary === 'string') { this.setBoundary(cfg.boundary) } else { this._bparser = undefined }
|
|
23
|
+
|
|
24
|
+
this._headerFirst = cfg.headerFirst
|
|
25
|
+
|
|
26
|
+
this._dashes = 0
|
|
27
|
+
this._parts = 0
|
|
28
|
+
this._finished = false
|
|
29
|
+
this._realFinish = false
|
|
30
|
+
this._isPreamble = true
|
|
31
|
+
this._justMatched = false
|
|
32
|
+
this._firstWrite = true
|
|
33
|
+
this._inHeader = true
|
|
34
|
+
this._part = undefined
|
|
35
|
+
this._cb = undefined
|
|
36
|
+
this._ignoreData = false
|
|
37
|
+
this._partOpts = { highWaterMark: cfg.partHwm }
|
|
38
|
+
this._pause = false
|
|
39
|
+
|
|
40
|
+
const self = this
|
|
41
|
+
this._hparser = new HeaderParser(cfg)
|
|
42
|
+
this._hparser.on('header', function (header) {
|
|
43
|
+
self._inHeader = false
|
|
44
|
+
self._part.emit('header', header)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
inherits(Dicer, WritableStream)
|
|
48
|
+
|
|
49
|
+
Dicer.prototype.emit = function (ev) {
|
|
50
|
+
if (ev === 'finish' && !this._realFinish) {
|
|
51
|
+
if (!this._finished) {
|
|
52
|
+
const self = this
|
|
53
|
+
process.nextTick(function () {
|
|
54
|
+
self.emit('error', new Error('Unexpected end of multipart data'))
|
|
55
|
+
if (self._part && !self._ignoreData) {
|
|
56
|
+
const type = (self._isPreamble ? 'Preamble' : 'Part')
|
|
57
|
+
self._part.emit('error', new Error(type + ' terminated early due to unexpected end of multipart data'))
|
|
58
|
+
self._part.push(null)
|
|
59
|
+
process.nextTick(function () {
|
|
60
|
+
self._realFinish = true
|
|
61
|
+
self.emit('finish')
|
|
62
|
+
self._realFinish = false
|
|
63
|
+
})
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
self._realFinish = true
|
|
67
|
+
self.emit('finish')
|
|
68
|
+
self._realFinish = false
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
} else { WritableStream.prototype.emit.apply(this, arguments) }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Dicer.prototype._write = function (data, encoding, cb) {
|
|
75
|
+
// ignore unexpected data (e.g. extra trailer data after finished)
|
|
76
|
+
if (!this._hparser && !this._bparser) { return cb() }
|
|
77
|
+
|
|
78
|
+
if (this._headerFirst && this._isPreamble) {
|
|
79
|
+
if (!this._part) {
|
|
80
|
+
this._part = new PartStream(this._partOpts)
|
|
81
|
+
if (this.listenerCount('preamble') !== 0) { this.emit('preamble', this._part) } else { this._ignore() }
|
|
82
|
+
}
|
|
83
|
+
const r = this._hparser.push(data)
|
|
84
|
+
if (!this._inHeader && r !== undefined && r < data.length) { data = data.slice(r) } else { return cb() }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// allows for "easier" testing
|
|
88
|
+
if (this._firstWrite) {
|
|
89
|
+
this._bparser.push(B_CRLF)
|
|
90
|
+
this._firstWrite = false
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this._bparser.push(data)
|
|
94
|
+
|
|
95
|
+
if (this._pause) { this._cb = cb } else { cb() }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Dicer.prototype.reset = function () {
|
|
99
|
+
this._part = undefined
|
|
100
|
+
this._bparser = undefined
|
|
101
|
+
this._hparser = undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Dicer.prototype.setBoundary = function (boundary) {
|
|
105
|
+
const self = this
|
|
106
|
+
this._bparser = new StreamSearch('\r\n--' + boundary)
|
|
107
|
+
this._bparser.on('info', function (isMatch, data, start, end) {
|
|
108
|
+
self._oninfo(isMatch, data, start, end)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Dicer.prototype._ignore = function () {
|
|
113
|
+
if (this._part && !this._ignoreData) {
|
|
114
|
+
this._ignoreData = true
|
|
115
|
+
this._part.on('error', EMPTY_FN)
|
|
116
|
+
// we must perform some kind of read on the stream even though we are
|
|
117
|
+
// ignoring the data, otherwise node's Readable stream will not emit 'end'
|
|
118
|
+
// after pushing null to the stream
|
|
119
|
+
this._part.resume()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Dicer.prototype._oninfo = function (isMatch, data, start, end) {
|
|
124
|
+
let buf; const self = this; let i = 0; let r; let shouldWriteMore = true
|
|
125
|
+
|
|
126
|
+
if (!this._part && this._justMatched && data) {
|
|
127
|
+
while (this._dashes < 2 && (start + i) < end) {
|
|
128
|
+
if (data[start + i] === DASH) {
|
|
129
|
+
++i
|
|
130
|
+
++this._dashes
|
|
131
|
+
} else {
|
|
132
|
+
if (this._dashes) { buf = B_ONEDASH }
|
|
133
|
+
this._dashes = 0
|
|
134
|
+
break
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (this._dashes === 2) {
|
|
138
|
+
if ((start + i) < end && this.listenerCount('trailer') !== 0) { this.emit('trailer', data.slice(start + i, end)) }
|
|
139
|
+
this.reset()
|
|
140
|
+
this._finished = true
|
|
141
|
+
// no more parts will be added
|
|
142
|
+
if (self._parts === 0) {
|
|
143
|
+
self._realFinish = true
|
|
144
|
+
self.emit('finish')
|
|
145
|
+
self._realFinish = false
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (this._dashes) { return }
|
|
149
|
+
}
|
|
150
|
+
if (this._justMatched) { this._justMatched = false }
|
|
151
|
+
if (!this._part) {
|
|
152
|
+
this._part = new PartStream(this._partOpts)
|
|
153
|
+
this._part._read = function (n) {
|
|
154
|
+
self._unpause()
|
|
155
|
+
}
|
|
156
|
+
if (this._isPreamble && this.listenerCount('preamble') !== 0) {
|
|
157
|
+
this.emit('preamble', this._part)
|
|
158
|
+
} else if (this._isPreamble !== true && this.listenerCount('part') !== 0) {
|
|
159
|
+
this.emit('part', this._part)
|
|
160
|
+
} else {
|
|
161
|
+
this._ignore()
|
|
162
|
+
}
|
|
163
|
+
if (!this._isPreamble) { this._inHeader = true }
|
|
164
|
+
}
|
|
165
|
+
if (data && start < end && !this._ignoreData) {
|
|
166
|
+
if (this._isPreamble || !this._inHeader) {
|
|
167
|
+
if (buf) { shouldWriteMore = this._part.push(buf) }
|
|
168
|
+
shouldWriteMore = this._part.push(data.slice(start, end))
|
|
169
|
+
if (!shouldWriteMore) { this._pause = true }
|
|
170
|
+
} else if (!this._isPreamble && this._inHeader) {
|
|
171
|
+
if (buf) { this._hparser.push(buf) }
|
|
172
|
+
r = this._hparser.push(data.slice(start, end))
|
|
173
|
+
if (!this._inHeader && r !== undefined && r < end) { this._oninfo(false, data, start + r, end) }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (isMatch) {
|
|
177
|
+
this._hparser.reset()
|
|
178
|
+
if (this._isPreamble) { this._isPreamble = false } else {
|
|
179
|
+
if (start !== end) {
|
|
180
|
+
++this._parts
|
|
181
|
+
this._part.on('end', function () {
|
|
182
|
+
if (--self._parts === 0) {
|
|
183
|
+
if (self._finished) {
|
|
184
|
+
self._realFinish = true
|
|
185
|
+
self.emit('finish')
|
|
186
|
+
self._realFinish = false
|
|
187
|
+
} else {
|
|
188
|
+
self._unpause()
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
this._part.push(null)
|
|
195
|
+
this._part = undefined
|
|
196
|
+
this._ignoreData = false
|
|
197
|
+
this._justMatched = true
|
|
198
|
+
this._dashes = 0
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Dicer.prototype._unpause = function () {
|
|
203
|
+
if (!this._pause) { return }
|
|
204
|
+
|
|
205
|
+
this._pause = false
|
|
206
|
+
if (this._cb) {
|
|
207
|
+
const cb = this._cb
|
|
208
|
+
this._cb = undefined
|
|
209
|
+
cb()
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = Dicer
|