(buffer, charset)
| 173 | * @returns {Promise<string>} |
| 174 | */ |
| 175 | export async function decode(buffer, charset) { |
| 176 | let isJson = false; |
| 177 | |
| 178 | if (charset === "json") { |
| 179 | charset = null; |
| 180 | isJson = true; |
| 181 | } |
| 182 | |
| 183 | charset = getEncodingName(charset); |
| 184 | const text = await execDecode(buffer, charset); |
| 185 | |
| 186 | if (isJson) { |
| 187 | return JSON.parse(text); |
| 188 | } |
| 189 | |
| 190 | return text; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Encodes text to ArrayBuffer according given encoding type |
no test coverage detected