summaryrefslogtreecommitdiff
path: root/node_modules/snekfetch/src/node/FormData.js
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:48:28 -0700
committer8cy <[email protected]>2020-04-03 02:48:28 -0700
commitf9159ea2d994e14180fb02ab562f0119513e67cf (patch)
tree09d14cdf05456567156738b681379d4bccd64e5c /node_modules/snekfetch/src/node/FormData.js
parent2020/04/03, 02:42, V1.2.1 (diff)
downloads5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz
s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/snekfetch/src/node/FormData.js')
-rw-r--r--node_modules/snekfetch/src/node/FormData.js51
1 files changed, 0 insertions, 51 deletions
diff --git a/node_modules/snekfetch/src/node/FormData.js b/node_modules/snekfetch/src/node/FormData.js
deleted file mode 100644
index f8270e2..0000000
--- a/node_modules/snekfetch/src/node/FormData.js
+++ /dev/null
@@ -1,51 +0,0 @@
-const path = require('path');
-const mime = require('./mime');
-
-class FormData {
- constructor() {
- this.boundary = `--snekfetch--${Math.random().toString().slice(2, 7)}`;
- this.buffers = [];
- }
-
- append(name, data, filename) {
- if (typeof data === 'undefined')
- return;
- let str = `\r\n--${this.boundary}\r\nContent-Disposition: form-data; name="${name}"`;
- let mimetype = null;
- if (filename) {
- str += `; filename="${filename}"`;
- mimetype = 'application/octet-stream';
- const extname = path.extname(filename).slice(1);
- if (extname)
- mimetype = mime.lookup(extname);
- }
-
- if (data instanceof Buffer) {
- mimetype = mime.buffer(data);
- } else if (typeof data === 'object') {
- mimetype = 'application/json';
- data = Buffer.from(JSON.stringify(data));
- } else {
- data = Buffer.from(String(data));
- }
-
- if (mimetype)
- str += `\r\nContent-Type: ${mimetype}`;
- this.buffers.push(Buffer.from(`${str}\r\n\r\n`));
- this.buffers.push(data);
- }
-
- getBoundary() {
- return this.boundary;
- }
-
- end() {
- return Buffer.concat([...this.buffers, Buffer.from(`\r\n--${this.boundary}--`)]);
- }
-
- get length() {
- return this.buffers.reduce((sum, b) => sum + Buffer.byteLength(b), 0);
- }
-}
-
-module.exports = FormData;