You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
869 B

4 years ago
  1. using Apewer;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Externals.Compression
  6. {
  7. internal static class Fixed
  8. {
  9. /// <summary>获取用于 Compression 的编码。参照字节数组获取编码,参照无效时获取默认编码。</summary>
  10. internal static Encoding GetEncoding(byte[] bytes = null)
  11. {
  12. // 识别参考数据,判断解压的编码。
  13. if (bytes != null || bytes.LongLength > 0L)
  14. {
  15. var isUTF8 = TextUtility.IsUTF8(bytes);
  16. if (isUTF8) return Encoding.UTF8;
  17. // 返回默认编码。
  18. #if NETFX
  19. return Encoding.Default;
  20. #else
  21. return Encoding.UTF8;
  22. #endif
  23. }
  24. // 用于压缩的默认编码。
  25. return Encoding.UTF8;
  26. }
  27. }
  28. }