Registry.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using SharpCompress.Common.SevenZip;
  5. using SharpCompress.Compressors.BZip2;
  6. using SharpCompress.Compressors.Deflate;
  7. using SharpCompress.Compressors.Filters;
  8. using SharpCompress.Compressors.LZMA.Utilites;
  9. using SharpCompress.Compressors.PPMd;
  10. namespace SharpCompress.Compressors.LZMA
  11. {
  12. internal static class DecoderRegistry
  13. {
  14. private const uint K_COPY = 0x0;
  15. private const uint K_DELTA = 3;
  16. private const uint K_LZMA2 = 0x21;
  17. private const uint K_LZMA = 0x030101;
  18. private const uint K_PPMD = 0x030401;
  19. private const uint K_BCJ = 0x03030103;
  20. private const uint K_BCJ2 = 0x0303011B;
  21. private const uint K_DEFLATE = 0x040108;
  22. private const uint K_B_ZIP2 = 0x040202;
  23. internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass,
  24. long limit)
  25. {
  26. switch (id._id)
  27. {
  28. case K_COPY:
  29. if (info != null)
  30. {
  31. throw new NotSupportedException();
  32. }
  33. return inStreams.Single();
  34. case K_LZMA:
  35. case K_LZMA2:
  36. return new LzmaStream(info, inStreams.Single(), -1, limit);
  37. #if !NO_CRYPTO
  38. case CMethodId.K_AES_ID:
  39. return new AesDecoderStream(inStreams.Single(), info, pass, limit);
  40. #endif
  41. case K_BCJ:
  42. return new BCJFilter(false, inStreams.Single());
  43. case K_BCJ2:
  44. return new Bcj2DecoderStream(inStreams, info, limit);
  45. case K_B_ZIP2:
  46. return new BZip2Stream(inStreams.Single(), CompressionMode.Decompress, true);
  47. case K_PPMD:
  48. return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false);
  49. case K_DEFLATE:
  50. return new DeflateStream(inStreams.Single(), CompressionMode.Decompress);
  51. default:
  52. throw new NotSupportedException();
  53. }
  54. }
  55. }
  56. }