| 20 | const ENCODINGS = TEXT_ENCODINGS.union(BINARY_ENCODINGS); |
| 21 | |
| 22 | const getCorrectEncoding = encoding => { |
| 23 | if (encoding === null) { |
| 24 | return 'buffer'; |
| 25 | } |
| 26 | |
| 27 | if (typeof encoding !== 'string') { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | const lowerEncoding = encoding.toLowerCase(); |
| 32 | if (lowerEncoding in ENCODING_ALIASES) { |
| 33 | return ENCODING_ALIASES[lowerEncoding]; |
| 34 | } |
| 35 | |
| 36 | if (ENCODINGS.has(lowerEncoding)) { |
| 37 | return lowerEncoding; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | const ENCODING_ALIASES = { |
| 42 | // eslint-disable-next-line unicorn/text-encoding-identifier-case |