// Based on the source code of the Body.textConverted method in node-fetch export function httpEncoding(header: string | null, content: Buffer): string | undefined { let res: RegExpExecArray | null = null; // header if (header) { res = /charset=([^;]*)/i.exec(header); } // no charset in content type, peek at response body for at most 1024 bytes const str = content.slice(0, 1024).toString(); // html5 if (!res && str) { res = /