SevenZipSharpWrapper.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Reflection;
  2. using SevenZip;
  3. namespace WarcViewerBlazorWinForm.Backend.IO.Archiving
  4. {
  5. internal static class SevenZipSharpWrapper
  6. {
  7. static SevenZipSharpWrapper()
  8. {
  9. // Toggle between the x86 and x64 bit dll
  10. var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
  11. SevenZipBase.SetLibraryPath(path);
  12. }
  13. // public static void WriteXz(string outputFilePath, Stream inputStream)
  14. // {
  15. // if (File.Exists(outputFilePath)) throw new IOException("Output file already exist");
  16. // var compressor = new SevenZipCompressor
  17. // {
  18. // CompressionLevel = CompressionLevel.Ultra,
  19. // CompressionMethod = CompressionMethod.Lzma2,
  20. // ArchiveFormat = OutArchiveFormat.XZ,
  21. // CompressionMode = CompressionMode.Create,
  22. // };
  23. // var outputMs = new MemoryStream();
  24. // compressor.CompressStream(inputStream, outputMs);
  25. // var bytes = outputMs.ToArray();
  26. // File.WriteAllBytes(outputFilePath, bytes);
  27. // }
  28. // public static byte[] ReadXz(string inputFilePath)
  29. // {
  30. // var ms = new MemoryStream();
  31. // var extractor = new SevenZipExtractor(inputFilePath);
  32. // extractor.ExtractFile(0, ms);
  33. // return ms.ToArray();
  34. // }
  35. }
  36. }