Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: '{build}'
image: Visual Studio 2017
image: Visual Studio 2019
configuration:
- Debug
- Release
Expand Down
Binary file added docs/sharpziplib-nuget-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BZip2Exception()
/// Initialise a new instance of <see cref="BZip2Exception" /> with its message string.
/// </summary>
/// <param name="message">A <see cref="string"/> that describes the error.</param>
public BZip2Exception(string message)
public BZip2Exception(string? message)
: base(message)
{
}
Expand All @@ -30,7 +30,7 @@ public BZip2Exception(string message)
/// </summary>
/// <param name="message">A <see cref="string"/> that describes the error.</param>
/// <param name="innerException">The <see cref="Exception"/> that caused this exception.</param>
public BZip2Exception(string message, Exception innerException)
public BZip2Exception(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand All @@ -46,7 +46,7 @@ public BZip2Exception(string message, Exception innerException)
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected BZip2Exception(SerializationInfo info, StreamingContext context)
protected BZip2Exception(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
21 changes: 11 additions & 10 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ICSharpCode.SharpZipLib.Checksum;
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.BZip2
{
Expand All @@ -9,7 +10,7 @@ namespace ICSharpCode.SharpZipLib.BZip2
/// </summary>
public class BZip2InputStream : Stream
{
#region Constants
#region Constants

private const int START_BLOCK_STATE = 1;
private const int RAND_PART_A_STATE = 2;
Expand All @@ -19,9 +20,9 @@ public class BZip2InputStream : Stream
private const int NO_RAND_PART_B_STATE = 6;
private const int NO_RAND_PART_C_STATE = 7;

#endregion Constants
#endregion Constants

#region Instance Fields
#region Instance Fields

/*--
index of the last char in the block, so
Expand Down Expand Up @@ -55,8 +56,8 @@ The current block size is 100000 * this number.
private byte[] selector = new byte[BZip2Constants.MaximumSelectors];
private byte[] selectorMtf = new byte[BZip2Constants.MaximumSelectors];

private int[] tt;
private byte[] ll8;
private int[] tt = EmptyRefs.Int32Array;
private byte[] ll8 = EmptyRefs.ByteArray;

/*--
freq table collected to save a pass over the data
Expand Down Expand Up @@ -87,7 +88,7 @@ during decompression.
private int i2, j2;
private byte z;

#endregion Instance Fields
#endregion Instance Fields

/// <summary>
/// Construct instance for reading from stream
Expand Down Expand Up @@ -119,7 +120,7 @@ public BZip2InputStream(Stream stream)
/// </summary>
public bool IsStreamOwner { get; set; } = true;

#region Stream Overrides
#region Stream Overrides

/// <summary>
/// Gets a value indicating if the stream supports reading
Expand Down Expand Up @@ -222,7 +223,7 @@ public override void SetLength(long value)
/// <param name="offset">The offset to start obtaining data from.</param>
/// <param name="count">The number of bytes of data to write.</param>
/// <exception cref="NotSupportedException">Any access</exception>
public override void Write(byte[] buffer, int offset, int count)
public override void Write(byte[]? buffer, int offset, int count)
{
throw new NotSupportedException("BZip2InputStream Write not supported");
}
Expand Down Expand Up @@ -316,7 +317,7 @@ public override int ReadByte()
return retChar;
}

#endregion Stream Overrides
#endregion Stream Overrides

private void MakeMaps()
{
Expand Down Expand Up @@ -746,7 +747,7 @@ cache misses.

private void SetupBlock()
{
int[] cftab = new int[257];
int[]? cftab = new int[257];

cftab[0] = 0;
Array.Copy(unzftab, 0, cftab, 1, 256);
Expand Down
21 changes: 11 additions & 10 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2OutputStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ICSharpCode.SharpZipLib.Checksum;
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.BZip2
{
Expand Down Expand Up @@ -79,11 +80,11 @@ The current block size is 100000 * this number.
private char[] selector = new char[BZip2Constants.MaximumSelectors];
private char[] selectorMtf = new char[BZip2Constants.MaximumSelectors];

private byte[] block;
private int[] quadrant;
private int[] zptr;
private short[] szptr;
private int[] ftab;
private byte[] block = EmptyRefs.ByteArray;
private int[] quadrant = EmptyRefs.Int32Array;
private int[] zptr = EmptyRefs.Int32Array;
private short[] szptr = EmptyRefs.Int16Array;
private int[] ftab = EmptyRefs.Int32Array;

private int nMTF;

Expand Down Expand Up @@ -266,7 +267,7 @@ public override int ReadByte()
/// <returns>The total number of bytes read. This might be less than the number of bytes
/// requested if that number of bytes are not currently available, or zero
/// if the end of the stream is reached.</returns>
public override int Read(byte[] buffer, int offset, int count)
public override int Read(byte[]? buffer, int offset, int count)
{
throw new NotSupportedException("BZip2OutputStream Read not supported");
}
Expand Down Expand Up @@ -710,14 +711,14 @@ private void SendMTFValues()
remF -= aFreq;
}

int[][] rfreq = new int[BZip2Constants.GroupCount][];
int[][]? rfreq = new int[BZip2Constants.GroupCount][];
for (int i = 0; i < BZip2Constants.GroupCount; ++i)
{
rfreq[i] = new int[BZip2Constants.MaximumAlphaSize];
}

int[] fave = new int[BZip2Constants.GroupCount];
short[] cost = new short[BZip2Constants.GroupCount];
int[]? fave = new int[BZip2Constants.GroupCount];
short[]? cost = new short[BZip2Constants.GroupCount];
/*---
Iterate up to N_ITERS times to improve the tables.
---*/
Expand Down Expand Up @@ -1691,7 +1692,7 @@ private void AllocateCompressStructures()
zptr = new int[n];
ftab = new int[65537];

if (block == null || quadrant == null || zptr == null || ftab == null)
if (block == EmptyRefs.ByteArray || quadrant == null || zptr == null || ftab == null)
{
// int totalDraw = (n + 1 + NUM_OVERSHOOT_BYTES) + (n + NUM_OVERSHOOT_BYTES) + n + 65537;
// compressOutOfMemory ( totalDraw, n );
Expand Down
22 changes: 22 additions & 0 deletions src/ICSharpCode.SharpZipLib/Core/EmptyRefs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;

namespace ICSharpCode.SharpZipLib.Core
{
internal static class EmptyRefs
{
#if NET45
public static byte[] ByteArray { get; } = new byte[0];
public static int[] Int32Array { get; } = new int[0];
public static short[] Int16Array {get; } = new short[0];
public static ZipEntry[] ZipEntryArray { get; } = new ZipEntry[0];
#else
public static byte[] ByteArray => Array.Empty<byte>();
public static int[] Int32Array => Array.Empty<int>();
public static short[] Int16Array => Array.Empty<short>();
public static ZipEntry[] ZipEntryArray => Array.Empty<ZipEntry>();
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SharpZipBaseException()
/// Initializes a new instance of the SharpZipBaseException class with a specified error message.
/// </summary>
/// <param name="message">A message describing the exception.</param>
public SharpZipBaseException(string message)
public SharpZipBaseException(string? message)
: base(message)
{
}
Expand All @@ -34,7 +34,7 @@ public SharpZipBaseException(string message)
/// </summary>
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public SharpZipBaseException(string message, Exception innerException)
public SharpZipBaseException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand All @@ -50,7 +50,7 @@ public SharpZipBaseException(string message, Exception innerException)
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected SharpZipBaseException(SerializationInfo info, StreamingContext context)
protected SharpZipBaseException(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public StreamDecodingException() : base(GenericMessage) { }
/// Initializes a new instance of the StreamDecodingException class with a specified error message.
/// </summary>
/// <param name="message">A message describing the exception.</param>
public StreamDecodingException(string message) : base(message) { }
public StreamDecodingException(string? message) : base(message) { }

/// <summary>
/// Initializes a new instance of the StreamDecodingException class with a specified
/// error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public StreamDecodingException(string message, Exception innerException) : base(message, innerException) { }
public StreamDecodingException(string? message, Exception? innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the StreamDecodingException class with serialized data.
Expand All @@ -42,7 +42,7 @@ public StreamDecodingException(string message, Exception innerException) : base(
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected StreamDecodingException(SerializationInfo info, StreamingContext context)
protected StreamDecodingException(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public StreamUnsupportedException() : base(GenericMessage) { }
/// Initializes a new instance of the StreamUnsupportedException class with a specified error message.
/// </summary>
/// <param name="message">A message describing the exception.</param>
public StreamUnsupportedException(string message) : base(message) { }
public StreamUnsupportedException(string? message) : base(message) { }

/// <summary>
/// Initializes a new instance of the StreamUnsupportedException class with a specified
/// error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public StreamUnsupportedException(string message, Exception innerException) : base(message, innerException) { }
public StreamUnsupportedException(string? message, Exception? innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the StreamUnsupportedException class with serialized data.
Expand All @@ -41,7 +41,7 @@ public StreamUnsupportedException(string message, Exception innerException) : ba
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected StreamUnsupportedException(SerializationInfo info, StreamingContext context)
protected StreamUnsupportedException(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public UnexpectedEndOfStreamException() : base(GenericMessage) { }
/// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified error message.
/// </summary>
/// <param name="message">A message describing the exception.</param>
public UnexpectedEndOfStreamException(string message) : base(message) { }
public UnexpectedEndOfStreamException(string? message) : base(message) { }

/// <summary>
/// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified
/// error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public UnexpectedEndOfStreamException(string message, Exception innerException) : base(message, innerException) { }
public UnexpectedEndOfStreamException(string? message, Exception? innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the UnexpectedEndOfStreamException class with serialized data.
Expand All @@ -41,7 +41,7 @@ public UnexpectedEndOfStreamException(string message, Exception innerException)
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected UnexpectedEndOfStreamException(SerializationInfo info, StreamingContext context)
protected UnexpectedEndOfStreamException(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ValueOutOfRangeException : StreamDecodingException
/// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable
/// </summary>
/// <param name="nameOfValue">Name of the variable, use: nameof()</param>
public ValueOutOfRangeException(string nameOfValue)
public ValueOutOfRangeException(string? nameOfValue)
: base($"{nameOfValue} out of range") { }

/// <summary>
Expand All @@ -24,7 +24,7 @@ public ValueOutOfRangeException(string nameOfValue)
/// <param name="value">The invalid value</param>
/// <param name="maxValue">Expected maximum value</param>
/// <param name="minValue">Expected minimum value</param>
public ValueOutOfRangeException(string nameOfValue, long value, long maxValue, long minValue = 0)
public ValueOutOfRangeException(string? nameOfValue, long value, long maxValue, long minValue = 0)
: this(nameOfValue, value.ToString(), maxValue.ToString(), minValue.ToString()) { }

/// <summary>
Expand All @@ -35,15 +35,15 @@ public ValueOutOfRangeException(string nameOfValue, long value, long maxValue, l
/// <param name="value">The invalid value</param>
/// <param name="maxValue">Expected maximum value</param>
/// <param name="minValue">Expected minimum value</param>
public ValueOutOfRangeException(string nameOfValue, string value, string maxValue, string minValue = "0") :
public ValueOutOfRangeException(string? nameOfValue, string? value, string? maxValue, string? minValue = "0") :
base($"{nameOfValue} out of range: {value}, should be {minValue}..{maxValue}")
{ }

private ValueOutOfRangeException()
{
}

private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException)
private ValueOutOfRangeException(string? message, Exception? innerException) : base(message, innerException)
{
}

Expand All @@ -58,7 +58,7 @@ private ValueOutOfRangeException(string message, Exception innerException) : bas
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected ValueOutOfRangeException(SerializationInfo info, StreamingContext context)
protected ValueOutOfRangeException(SerializationInfo? info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Loading