/// <summary> /// 判断得到文件的编码内容判断结果响应 /// </summary> /// <param name="file">文件内容</param> /// <returns>编码内容判断结果响应</returns> public static JudgeEncodingResponse GetJudgeEncodingResponse(this FileInfo file) { JudgeEncodingResponse response = GetDefaultResponse(); byte[] contentBytes = null; foreach (var item in GetJudgeEncodings()) { bool isNullContentBytes = contentBytes == null || contentBytes.Length <= 0; response = isNullContentBytes ? item.GetEncoding(file) : item.GetEncoding(contentBytes); if (response.Encoding != null) { return(response); } if (response.IsReadFileALLContent) { contentBytes = response.ContentBytes; } } return(response); }
/// <summary> /// 判断得到文件的编码内容 /// </summary> /// <param name="file">文件内容</param> /// <returns>编码结果, 如果不受支持无法找到则返回 NULL</returns> public static Encoding GetEncoding(this FileInfo file) { JudgeEncodingResponse response = file.GetJudgeEncodingResponse(); return(response.Encoding?.ToEncoding()); }