Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,69 @@ namespace ICSharpCode.SharpZipLib.BZip2
public static class BZip2
{
/// <summary>
/// Decompress the <paramref name="inStream">input</paramref> writing
/// Decompress the <paramref name="inStream">input</paramref> writing
/// uncompressed data to the <paramref name="outStream">output stream</paramref>
/// </summary>
/// <param name="inStream">The readable stream containing data to decompress.</param>
/// <param name="outStream">The output stream to receive the decompressed data.</param>
/// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner)
{
if (inStream == null || outStream == null) {
if (inStream == null || outStream == null)
{
throw new Exception("Null Stream");
}

try {
using (BZip2InputStream bzipInput = new BZip2InputStream(inStream)) {
try
{
using (BZip2InputStream bzipInput = new BZip2InputStream(inStream))
{
bzipInput.IsStreamOwner = isStreamOwner;
Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]);
}
} finally {
if (isStreamOwner) {
}
finally
{
if (isStreamOwner)
{
// inStream is closed by the BZip2InputStream if stream owner
outStream.Dispose();
}
}
}

/// <summary>
/// Compress the <paramref name="inStream">input stream</paramref> sending
/// Compress the <paramref name="inStream">input stream</paramref> sending
/// result data to <paramref name="outStream">output stream</paramref>
/// </summary>
/// <param name="inStream">The readable stream to compress.</param>
/// <param name="outStream">The output stream to receive the compressed data.</param>
/// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
/// <param name="level">Block size acts as compression level (1 to 9) with 1 giving
/// <param name="level">Block size acts as compression level (1 to 9) with 1 giving
/// the lowest compression and 9 the highest.</param>
public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
{
if (inStream == null || outStream == null) {
if (inStream == null || outStream == null)
{
throw new Exception("Null Stream");
}

try {
using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level)) {
try
{
using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level))
{
bzipOutput.IsStreamOwner = isStreamOwner;
Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
}
} finally {
if (isStreamOwner) {
}
finally
{
if (isStreamOwner)
{
// outStream is closed by the BZip2OutputStream if stream owner
inStream.Dispose();
}
}
}

}
}
2 changes: 1 addition & 1 deletion src/ICSharpCode.SharpZipLib/BZip2/BZip2Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal sealed class BZip2Constants
/// <summary>
/// When multiplied by compression parameter (1-9) gives the block size for compression
/// 9 gives the best compression but uses the most memory.
/// </summary>
/// </summary>
public const int BaseBlockSize = 100000;

/// <summary>
Expand Down
Loading