Summary

Class:ICSharpCode.SharpZipLib.BZip2.BZip2
Assembly:ICSharpCode.SharpZipLib
File(s):C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\BZip2\BZip2.cs
Covered lines:0
Uncovered lines:20
Coverable lines:20
Total lines:66
Line coverage:0%
Branch coverage:0%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
Decompress(...)500
Compress(...)500

File(s)

C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\BZip2\BZip2.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3
 4namespace ICSharpCode.SharpZipLib.BZip2
 5{
 6  /// <summary>
 7  /// An example class to demonstrate compression and decompression of BZip2 streams.
 8  /// </summary>
 9  public static class BZip2
 10  {
 11    /// <summary>
 12    /// Decompress the <paramref name="inStream">input</paramref> writing
 13    /// uncompressed data to the <paramref name="outStream">output stream</paramref>
 14    /// </summary>
 15    /// <param name="inStream">The readable stream containing data to decompress.</param>
 16    /// <param name="outStream">The output stream to receive the decompressed data.</param>
 17    /// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
 18    public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner)
 19    {
 020       if (inStream == null || outStream == null) {
 021        throw new Exception("Null Stream");
 22      }
 23
 24      try {
 025        using (BZip2InputStream bzipInput = new BZip2InputStream(inStream)) {
 026          bzipInput.IsStreamOwner = isStreamOwner;
 027          Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]);
 028        }
 29      } finally {
 030         if (isStreamOwner) {
 31          // inStream is closed by the BZip2InputStream if stream owner
 032          outStream.Close();
 33        }
 034      }
 035    }
 36
 37    /// <summary>
 38    /// Compress the <paramref name="inStream">input stream</paramref> sending
 39    /// result data to <paramref name="outStream">output stream</paramref>
 40    /// </summary>
 41    /// <param name="inStream">The readable stream to compress.</param>
 42    /// <param name="outStream">The output stream to receive the compressed data.</param>
 43    /// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
 44    /// <param name="level">Block size acts as compression level (1 to 9) with 1 giving
 45    /// the lowest compression and 9 the highest.</param>
 46    public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
 47    {
 048       if (inStream == null || outStream == null) {
 049        throw new Exception("Null Stream");
 50      }
 51
 52      try {
 053        using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level)) {
 054          bzipOutput.IsStreamOwner = isStreamOwner;
 055          Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
 056        }
 57      } finally {
 058         if (isStreamOwner) {
 59          // outStream is closed by the BZip2OutputStream if stream owner
 060          inStream.Close();
 61        }
 062      }
 063    }
 64
 65  }
 66}