summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
commitdc04ca93060443a3ce6263a476f4dafc66afc6b3 (patch)
treeb9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
parentUpdate config supports_message_history (diff)
downloadgpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.gz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.bz2
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.lz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.xz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.zst
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.zip
Diffstat (limited to 'g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js')
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
new file mode 100644
index 00000000..7917678c
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
@@ -0,0 +1,54 @@
+'use strict'
+
+const RE_PLUS = /\+/g
+
+const HEX = [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+]
+
+function Decoder () {
+ this.buffer = undefined
+}
+Decoder.prototype.write = function (str) {
+ // Replace '+' with ' ' before decoding
+ str = str.replace(RE_PLUS, ' ')
+ let res = ''
+ let i = 0; let p = 0; const len = str.length
+ for (; i < len; ++i) {
+ if (this.buffer !== undefined) {
+ if (!HEX[str.charCodeAt(i)]) {
+ res += '%' + this.buffer
+ this.buffer = undefined
+ --i // retry character
+ } else {
+ this.buffer += str[i]
+ ++p
+ if (this.buffer.length === 2) {
+ res += String.fromCharCode(parseInt(this.buffer, 16))
+ this.buffer = undefined
+ }
+ }
+ } else if (str[i] === '%') {
+ if (i > p) {
+ res += str.substring(p, i)
+ p = i
+ }
+ this.buffer = ''
+ ++p
+ }
+ }
+ if (p < len && this.buffer === undefined) { res += str.substring(p) }
+ return res
+}
+Decoder.prototype.reset = function () {
+ this.buffer = undefined
+}
+
+module.exports = Decoder