Skip to content
Closed
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
5 changes: 5 additions & 0 deletions ICSharpCode.SharpZipLib.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IV/@EntryIndexedValue">IV</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=decryptor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deflater/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=encryptor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
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.
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 = Empty.Array<int>();
private byte[] ll8 = Empty.Array<byte>();

/*--
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 = Empty.Array<byte>();
private int[] quadrant = Empty.Array<int>();
private int[] zptr = Empty.Array<int>();
private short[] szptr = Empty.Array<short>();
private int[] ftab = Empty.Array<int>();

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 == Empty.Array<byte>() || quadrant == null || zptr == null || ftab == null)
{
// int totalDraw = (n + 1 + NUM_OVERSHOOT_BYTES) + (n + NUM_OVERSHOOT_BYTES) + n + 65537;
// compressOutOfMemory ( totalDraw, n );
Expand Down
20 changes: 20 additions & 0 deletions src/ICSharpCode.SharpZipLib/Core/EmptyRefs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;

namespace ICSharpCode.SharpZipLib.Core
{
internal static class Empty
{
#if NET45
internal static class EmptyArray<T>
{
public static readonly T[] Value = new T[0];
}
public static T[] Array<T>() => EmptyArray<T>.Value;
#else
public static T[] Array<T>() => System.Array.Empty<T>();
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ICSharpCode.SharpZipLib
{
/// <summary>
/// Indicates that an error occured during decoding of a input stream due to corrupt
/// data or (unintentional) library incompability.
/// data or (unintentional) library incompatibility.
/// </summary>
[Serializable]
public class StreamDecodingException : SharpZipBaseException
Expand Down
Loading