1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-07-01 23:23:38 +00:00
This commit is contained in:
MatteZ02
2019-10-10 16:43:04 +03:00
parent 6f6ac8a6fa
commit 50b9bed483
9432 changed files with 1988816 additions and 167 deletions

51
node_modules/snekfetch/src/node/FormData.js generated vendored Normal file
View File

@ -0,0 +1,51 @@
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;