* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain|Promise} Encoded content
(content)
| 32 | * @return {number[]|string|Uint8Array|Chain|Promise} Encoded content |
| 33 | */ |
| 34 | performEncode (content) { |
| 35 | try { |
| 36 | // Try to URL encode string representation of content |
| 37 | const chars = content.getChars() |
| 38 | let string = '' |
| 39 | let char |
| 40 | for (let i = 0; i < chars.length; i++) { |
| 41 | char = chars[i] |
| 42 | string += unreservedURLCharacters.indexOf(char) === -1 |
| 43 | ? this.encodeBytes(content.getCharBytesAt(i)) |
| 44 | : char |
| 45 | } |
| 46 | return string |
| 47 | } catch (error) { |
| 48 | // Retrieving the string representation of the content may throw an error |
| 49 | // due to bad UTF-8 encoded text |
| 50 | if (error instanceof TextEncodingError) { |
| 51 | // Encode raw bytes (which do not need to be valid UTF-8) |
| 52 | return this.encodeBytes(content.getBytes()) |
| 53 | } else { |
| 54 | throw error |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Percent-encode bytes. |
nothing calls this directly
no test coverage detected