Spaces:
Sleeping
Sleeping
Download node_modules/@fastify/busboy/lib/utils/decodeText.js from carpool-team/Carpool: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/carpool-team/Carpool/resolve/main/node_modules/%40fastify/busboy/lib/utils/decodeText.js
- Command line
-
hf download hf://spaces/carpool-team/Carpool/node_modules/@fastify/busboy/lib/utils/decodeText.js
-
curl -L -o decodeText.js https://huggingface.co/spaces/carpool-team/Carpool/resolve/main/node_modules/%40fastify/busboy/lib/utils/decodeText.js
1.77 kB
| let TextDecoder | |
| try { | |
| TextDecoder = require('util').TextDecoder | |
| } catch (e) { } | |
| const { TextDecoder: PolyfillTextDecoder, getEncoding } = require('text-decoding') | |
| // Node has always utf-8 | |
| const textDecoders = new Map() | |
| if (TextDecoder) { | |
| textDecoders.set('utf-8', new TextDecoder('utf-8')) | |
| } else { | |
| textDecoders.set('utf-8', new PolyfillTextDecoder('utf-8')) | |
| } | |
| textDecoders.set('utf8', textDecoders.get('utf-8')) | |
| function decodeText (text, textEncoding, destEncoding) { | |
| if (text) { | |
| if (textDecoders.has(destEncoding)) { | |
| try { | |
| return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding)) | |
| } catch (e) { } | |
| } else { | |
| try { | |
| textDecoders.set(destEncoding, new TextDecoder(destEncoding)) | |
| return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding)) | |
| } catch (e) { | |
| if (getEncoding(destEncoding)) { | |
| try { | |
| textDecoders.set(destEncoding, new PolyfillTextDecoder(destEncoding)) | |
| return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding)) | |
| } catch (e) { } | |
| } | |
| } | |
| } | |
| } | |
| return text | |
| } | |
| function decodeTextPolyfill (text, textEncoding, destEncoding) { | |
| if (text) { | |
| if (textDecoders.has(destEncoding)) { | |
| try { | |
| return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding)) | |
| } catch (e) { } | |
| } else { | |
| if (getEncoding(destEncoding)) { | |
| try { | |
| textDecoders.set(destEncoding, new PolyfillTextDecoder(destEncoding)) | |
| return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding)) | |
| } catch (e) { } | |
| } | |
| } | |
| } | |
| return text | |
| } | |
| module.exports = TextDecoder ? decodeText : decodeTextPolyfill | |