summaryrefslogtreecommitdiff
path: root/together/node_modules/formidable/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'together/node_modules/formidable/src/plugins')
-rw-r--r--together/node_modules/formidable/src/plugins/index.js13
-rw-r--r--together/node_modules/formidable/src/plugins/json.js38
-rw-r--r--together/node_modules/formidable/src/plugins/multipart.js173
-rw-r--r--together/node_modules/formidable/src/plugins/octetstream.js86
-rw-r--r--together/node_modules/formidable/src/plugins/querystring.js42
5 files changed, 0 insertions, 352 deletions
diff --git a/together/node_modules/formidable/src/plugins/index.js b/together/node_modules/formidable/src/plugins/index.js
deleted file mode 100644
index cbd491a..0000000
--- a/together/node_modules/formidable/src/plugins/index.js
+++ /dev/null
@@ -1,13 +0,0 @@
-'use strict';
-
-const octetstream = require('./octetstream');
-const querystring = require('./querystring');
-const multipart = require('./multipart');
-const json = require('./json');
-
-Object.assign(exports, {
- octetstream,
- querystring,
- multipart,
- json,
-});
diff --git a/together/node_modules/formidable/src/plugins/json.js b/together/node_modules/formidable/src/plugins/json.js
deleted file mode 100644
index 20d3b26..0000000
--- a/together/node_modules/formidable/src/plugins/json.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/* eslint-disable no-underscore-dangle */
-
-'use strict';
-
-const JSONParser = require('../parsers/JSON');
-
-// the `options` is also available through the `this.options` / `formidable.options`
-module.exports = function plugin(formidable, options) {
- // the `this` context is always formidable, as the first argument of a plugin
- // but this allows us to customize/test each plugin
-
- /* istanbul ignore next */
- const self = this || formidable;
-
- if (/json/i.test(self.headers['content-type'])) {
- init.call(self, self, options);
- }
-};
-
-// Note that it's a good practice (but it's up to you) to use the `this.options` instead
-// of the passed `options` (second) param, because when you decide
-// to test the plugin you can pass custom `this` context to it (and so `this.options`)
-function init(_self, _opts) {
- this.type = 'json';
-
- const parser = new JSONParser(this.options);
-
- parser.on('data', ({ key, value }) => {
- this.emit('field', key, value);
- });
-
- parser.once('end', () => {
- this.ended = true;
- this._maybeEnd();
- });
-
- this._parser = parser;
-}
diff --git a/together/node_modules/formidable/src/plugins/multipart.js b/together/node_modules/formidable/src/plugins/multipart.js
deleted file mode 100644
index ba07373..0000000
--- a/together/node_modules/formidable/src/plugins/multipart.js
+++ /dev/null
@@ -1,173 +0,0 @@
-/* eslint-disable no-underscore-dangle */
-
-'use strict';
-
-const { Stream } = require('stream');
-const MultipartParser = require('../parsers/Multipart');
-const errors = require('../FormidableError.js');
-
-const { FormidableError } = errors;
-
-// the `options` is also available through the `options` / `formidable.options`
-module.exports = function plugin(formidable, options) {
- // the `this` context is always formidable, as the first argument of a plugin
- // but this allows us to customize/test each plugin
-
- /* istanbul ignore next */
- const self = this || formidable;
-
- // NOTE: we (currently) support both multipart/form-data and multipart/related
- const multipart = /multipart/i.test(self.headers['content-type']);
-
- if (multipart) {
- const m = self.headers['content-type'].match(
- /boundary=(?:"([^"]+)"|([^;]+))/i,
- );
- if (m) {
- const initMultipart = createInitMultipart(m[1] || m[2]);
- initMultipart.call(self, self, options); // lgtm [js/superfluous-trailing-arguments]
- } else {
- const err = new FormidableError(
- 'bad content-type header, no multipart boundary',
- errors.missingMultipartBoundary,
- 400,
- );
- self._error(err);
- }
- }
-};
-
-// Note that it's a good practice (but it's up to you) to use the `this.options` instead
-// of the passed `options` (second) param, because when you decide
-// to test the plugin you can pass custom `this` context to it (and so `this.options`)
-function createInitMultipart(boundary) {
- return function initMultipart() {
- this.type = 'multipart';
-
- const parser = new MultipartParser(this.options);
- let headerField;
- let headerValue;
- let part;
-
- parser.initWithBoundary(boundary);
-
- // eslint-disable-next-line max-statements, consistent-return
- parser.on('data', ({ name, buffer, start, end }) => {
- if (name === 'partBegin') {
- part = new Stream();
- part.readable = true;
- part.headers = {};
- part.name = null;
- part.originalFilename = null;
- part.mimetype = null;
-
- part.transferEncoding = this.options.encoding;
- part.transferBuffer = '';
-
- headerField = '';
- headerValue = '';
- } else if (name === 'headerField') {
- headerField += buffer.toString(this.options.encoding, start, end);
- } else if (name === 'headerValue') {
- headerValue += buffer.toString(this.options.encoding, start, end);
- } else if (name === 'headerEnd') {
- headerField = headerField.toLowerCase();
- part.headers[headerField] = headerValue;
-
- // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
- const m = headerValue.match(
- // eslint-disable-next-line no-useless-escape
- /\bname=("([^"]*)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))/i,
- );
- if (headerField === 'content-disposition') {
- if (m) {
- part.name = m[2] || m[3] || '';
- }
-
- part.originalFilename = this._getFileName(headerValue);
- } else if (headerField === 'content-type') {
- part.mimetype = headerValue;
- } else if (headerField === 'content-transfer-encoding') {
- part.transferEncoding = headerValue.toLowerCase();
- }
-
- headerField = '';
- headerValue = '';
- } else if (name === 'headersEnd') {
- switch (part.transferEncoding) {
- case 'binary':
- case '7bit':
- case '8bit':
- case 'utf-8': {
- const dataPropagation = (ctx) => {
- if (ctx.name === 'partData') {
- part.emit('data', ctx.buffer.slice(ctx.start, ctx.end));
- }
- };
- const dataStopPropagation = (ctx) => {
- if (ctx.name === 'partEnd') {
- part.emit('end');
- parser.off('data', dataPropagation);
- parser.off('data', dataStopPropagation);
- }
- };
- parser.on('data', dataPropagation);
- parser.on('data', dataStopPropagation);
- break;
- }
- case 'base64': {
- const dataPropagation = (ctx) => {
- if (ctx.name === 'partData') {
- part.transferBuffer += ctx.buffer
- .slice(ctx.start, ctx.end)
- .toString('ascii');
-
- /*
- four bytes (chars) in base64 converts to three bytes in binary
- encoding. So we should always work with a number of bytes that
- can be divided by 4, it will result in a number of buytes that
- can be divided vy 3.
- */
- const offset = parseInt(part.transferBuffer.length / 4, 10) * 4;
- part.emit(
- 'data',
- Buffer.from(
- part.transferBuffer.substring(0, offset),
- 'base64',
- ),
- );
- part.transferBuffer = part.transferBuffer.substring(offset);
- }
- };
- const dataStopPropagation = (ctx) => {
- if (ctx.name === 'partEnd') {
- part.emit('data', Buffer.from(part.transferBuffer, 'base64'));
- part.emit('end');
- parser.off('data', dataPropagation);
- parser.off('data', dataStopPropagation);
- }
- };
- parser.on('data', dataPropagation);
- parser.on('data', dataStopPropagation);
- break;
- }
- default:
- return this._error(
- new FormidableError(
- 'unknown transfer-encoding',
- errors.unknownTransferEncoding,
- 501,
- ),
- );
- }
-
- this.onPart(part);
- } else if (name === 'end') {
- this.ended = true;
- this._maybeEnd();
- }
- });
-
- this._parser = parser;
- };
-}
diff --git a/together/node_modules/formidable/src/plugins/octetstream.js b/together/node_modules/formidable/src/plugins/octetstream.js
deleted file mode 100644
index 96fee40..0000000
--- a/together/node_modules/formidable/src/plugins/octetstream.js
+++ /dev/null
@@ -1,86 +0,0 @@
-/* eslint-disable no-underscore-dangle */
-
-'use strict';
-
-const OctetStreamParser = require('../parsers/OctetStream');
-
-// the `options` is also available through the `options` / `formidable.options`
-module.exports = function plugin(formidable, options) {
- // the `this` context is always formidable, as the first argument of a plugin
- // but this allows us to customize/test each plugin
-
- /* istanbul ignore next */
- const self = this || formidable;
-
- if (/octet-stream/i.test(self.headers['content-type'])) {
- init.call(self, self, options);
- }
-
- return self;
-};
-
-// Note that it's a good practice (but it's up to you) to use the `this.options` instead
-// of the passed `options` (second) param, because when you decide
-// to test the plugin you can pass custom `this` context to it (and so `this.options`)
-function init(_self, _opts) {
- this.type = 'octet-stream';
- const originalFilename = this.headers['x-file-name'];
- const mimetype = this.headers['content-type'];
-
- const thisPart = {
- originalFilename,
- mimetype,
- };
- const newFilename = this._getNewName(thisPart);
- const filepath = this._joinDirectoryName(newFilename);
- const file = this._newFile({
- newFilename,
- filepath,
- originalFilename,
- mimetype,
- });
-
- this.emit('fileBegin', originalFilename, file);
- file.open();
- this.openedFiles.push(file);
- this._flushing += 1;
-
- this._parser = new OctetStreamParser(this.options);
-
- // Keep track of writes that haven't finished so we don't emit the file before it's done being written
- let outstandingWrites = 0;
-
- this._parser.on('data', (buffer) => {
- this.pause();
- outstandingWrites += 1;
-
- file.write(buffer, () => {
- outstandingWrites -= 1;
- this.resume();
-
- if (this.ended) {
- this._parser.emit('doneWritingFile');
- }
- });
- });
-
- this._parser.on('end', () => {
- this._flushing -= 1;
- this.ended = true;
-
- const done = () => {
- file.end(() => {
- this.emit('file', 'file', file);
- this._maybeEnd();
- });
- };
-
- if (outstandingWrites === 0) {
- done();
- } else {
- this._parser.once('doneWritingFile', done);
- }
- });
-
- return this;
-}
diff --git a/together/node_modules/formidable/src/plugins/querystring.js b/together/node_modules/formidable/src/plugins/querystring.js
deleted file mode 100644
index c9dcf1e..0000000
--- a/together/node_modules/formidable/src/plugins/querystring.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/* eslint-disable no-underscore-dangle */
-
-'use strict';
-
-const QuerystringParser = require('../parsers/Querystring');
-
-// the `options` is also available through the `this.options` / `formidable.options`
-module.exports = function plugin(formidable, options) {
- // the `this` context is always formidable, as the first argument of a plugin
- // but this allows us to customize/test each plugin
-
- /* istanbul ignore next */
- const self = this || formidable;
-
- if (/urlencoded/i.test(self.headers['content-type'])) {
- init.call(self, self, options);
- }
-
- return self;
-};
-
-// Note that it's a good practice (but it's up to you) to use the `this.options` instead
-// of the passed `options` (second) param, because when you decide
-// to test the plugin you can pass custom `this` context to it (and so `this.options`)
-function init(_self, _opts) {
- this.type = 'urlencoded';
-
- const parser = new QuerystringParser(this.options);
-
- parser.on('data', ({ key, value }) => {
- this.emit('field', key, value);
- });
-
- parser.once('end', () => {
- this.ended = true;
- this._maybeEnd();
- });
-
- this._parser = parser;
-
- return this;
-}