Cleaned up public facing API

This commit is contained in:
Adam Hathcock
2013-04-28 12:30:18 +01:00
parent 5e6501704b
commit 2fe769afbb
9 changed files with 1270 additions and 1264 deletions

View File

@@ -6,7 +6,7 @@ using SharpCompress.Compressor.LZMA.Utilites;
namespace SharpCompress.Common.SevenZip
{
public class ArchiveDatabase
internal class ArchiveDatabase
{
internal byte MajorVersion;
internal byte MinorVersion;
@@ -50,7 +50,7 @@ namespace SharpCompress.Common.SevenZip
PackStreamStartPositions.Clear();
long startPos = 0;
for(int i = 0; i < PackSizes.Count; i++)
for (int i = 0; i < PackSizes.Count; i++)
{
PackStreamStartPositions.Add(startPos);
startPos += PackSizes[i];
@@ -64,30 +64,30 @@ namespace SharpCompress.Common.SevenZip
int folderIndex = 0;
int indexInFolder = 0;
for(int i = 0; i < Files.Count; i++)
for (int i = 0; i < Files.Count; i++)
{
CFileItem file = Files[i];
bool emptyStream = !file.HasStream;
if(emptyStream && indexInFolder == 0)
if (emptyStream && indexInFolder == 0)
{
FileIndexToFolderIndexMap.Add(-1);
continue;
}
if(indexInFolder == 0)
if (indexInFolder == 0)
{
// v3.13 incorrectly worked with empty folders
// v4.07: Loop for skipping empty folders
for(; ; )
for (; ; )
{
if(folderIndex >= Folders.Count)
if (folderIndex >= Folders.Count)
throw new InvalidOperationException();
FolderStartFileIndex.Add(i); // check it
if(NumUnpackStreamsVector[folderIndex] != 0)
if (NumUnpackStreamsVector[folderIndex] != 0)
break;
folderIndex++;
@@ -96,12 +96,12 @@ namespace SharpCompress.Common.SevenZip
FileIndexToFolderIndexMap.Add(folderIndex);
if(emptyStream)
if (emptyStream)
continue;
indexInFolder++;
if(indexInFolder >= NumUnpackStreamsVector[folderIndex])
if (indexInFolder >= NumUnpackStreamsVector[folderIndex])
{
folderIndex++;
indexInFolder = 0;
@@ -127,7 +127,7 @@ namespace SharpCompress.Common.SevenZip
CFolder folder = Folders[folderIndex];
long size = 0;
for(int i = 0; i < folder.PackStreams.Count; i++)
for (int i = 0; i < folder.PackStreams.Count; i++)
size += PackSizes[packStreamIndex + i];
return size;
@@ -135,13 +135,13 @@ namespace SharpCompress.Common.SevenZip
internal Stream GetFolderStream(Stream stream, CFolder folder, IPasswordProvider pw)
{
int packStreamIndex = folder.FirstPackStreamId;
long folderStartPackPos = GetFolderStreamPos(folder, 0);
List<long> packSizes = new List<long>();
for (int j = 0; j < folder.PackStreams.Count; j++)
packSizes.Add(PackSizes[packStreamIndex + j]);
int packStreamIndex = folder.FirstPackStreamId;
long folderStartPackPos = GetFolderStreamPos(folder, 0);
List<long> packSizes = new List<long>();
for (int j = 0; j < folder.PackStreams.Count; j++)
packSizes.Add(PackSizes[packStreamIndex + j]);
return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes.ToArray(), folder, pw);
return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes.ToArray(), folder, pw);
}
private long GetFolderPackStreamSize(int folderIndex, int streamIndex)
@@ -152,8 +152,8 @@ namespace SharpCompress.Common.SevenZip
private long GetFilePackSize(int fileIndex)
{
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if(folderIndex != -1)
if(FolderStartFileIndex[folderIndex] == fileIndex)
if (folderIndex != -1)
if (FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,33 +2,33 @@
namespace SharpCompress.Common.SevenZip
{
public class CFileItem
{
public long Size { get; internal set; }
public uint? Attrib { get; internal set; }
public uint? Crc { get; internal set; }
public string Name { get; internal set; }
internal class CFileItem
{
public long Size { get; internal set; }
public uint? Attrib { get; internal set; }
public uint? Crc { get; internal set; }
public string Name { get; internal set; }
public bool HasStream { get; internal set; }
public bool IsDir { get; internal set; }
public bool CrcDefined { get { return Crc != null; } }
public bool AttribDefined { get { return Attrib != null; } }
public bool HasStream { get; internal set; }
public bool IsDir { get; internal set; }
public bool CrcDefined { get { return Crc != null; } }
public bool AttribDefined { get { return Attrib != null; } }
public void SetAttrib(uint attrib)
{
this.Attrib = attrib;
}
public void SetAttrib(uint attrib)
{
this.Attrib = attrib;
}
public DateTime? CTime { get; internal set; }
public DateTime? ATime { get; internal set; }
public DateTime? MTime { get; internal set; }
public DateTime? CTime { get; internal set; }
public DateTime? ATime { get; internal set; }
public DateTime? MTime { get; internal set; }
public long? StartPos { get; internal set; }
public bool IsAnti { get; internal set; }
public long? StartPos { get; internal set; }
public bool IsAnti { get; internal set; }
internal CFileItem()
{
HasStream = true;
}
}
internal CFileItem()
{
HasStream = true;
}
}
}

View File

@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace SharpCompress.Compressor.Filters
{
public class BCJ2Filter : Stream
internal class BCJ2Filter : Stream
{
private Stream baseStream;
private byte[] input = new byte[4096];
private readonly Stream baseStream;
private readonly byte[] input = new byte[4096];
private int inputOffset = 0;
private int inputCount = 0;
private bool endReached = false;
@@ -136,7 +133,7 @@ namespace SharpCompress.Compressor.Filters
buffer[offset++] = b;
size++;
position++;
if (!IsJ(prevByte, b))
prevByte = b;
else

View File

@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO;
namespace SharpCompress.Compressor.Filters
{
public class BCJFilter : Filter
internal class BCJFilter : Filter
{
private static readonly bool[] MASK_TO_ALLOWED_STATUS = new bool[] {true, true, true, false, true, false, false, false};
private static readonly bool[] MASK_TO_ALLOWED_STATUS = new bool[] { true, true, true, false, true, false, false, false };
private static readonly int[] MASK_TO_BIT_NUMBER = new int[] { 0, 1, 2, 2, 3, 3, 3, 3 };
private int pos;
private int prevMask = 0;
public BCJFilter(bool isEncoder, Stream baseStream) : base(isEncoder, baseStream, 5)
public BCJFilter(bool isEncoder, Stream baseStream)
: base(isEncoder, baseStream, 5)
{
pos = 5;
}
@@ -30,18 +27,24 @@ namespace SharpCompress.Compressor.Filters
int end = offset + count - 5;
int i;
for (i = offset; i <= end; ++i) {
for (i = offset; i <= end; ++i)
{
if ((buffer[i] & 0xFE) != 0xE8)
continue;
prevPos = i - prevPos;
if ((prevPos & ~3) != 0) { // (unsigned)prevPos > 3
if ((prevPos & ~3) != 0)
{ // (unsigned)prevPos > 3
prevMask = 0;
} else {
}
else
{
prevMask = (prevMask << (prevPos - 1)) & 7;
if (prevMask != 0) {
if (prevMask != 0)
{
if (!MASK_TO_ALLOWED_STATUS[prevMask] || test86MSByte(
buffer[i + 4 - MASK_TO_BIT_NUMBER[prevMask]])) {
buffer[i + 4 - MASK_TO_BIT_NUMBER[prevMask]]))
{
prevPos = i;
prevMask = (prevMask << 1) | 1;
continue;
@@ -51,13 +54,15 @@ namespace SharpCompress.Compressor.Filters
prevPos = i;
if (test86MSByte(buffer[i + 4])) {
if (test86MSByte(buffer[i + 4]))
{
int src = buffer[i + 1]
| (buffer[i + 2] << 8)
| (buffer[i + 3] << 16)
| (buffer[i + 4] << 24);
int dest;
while (true) {
while (true)
{
if (isEncoder)
dest = src + (pos + i - offset);
else
@@ -78,7 +83,9 @@ namespace SharpCompress.Compressor.Filters
buffer[i + 3] = (byte)(dest >> 16);
buffer[i + 4] = (byte)(~(((dest >> 24) & 1) - 1));
i += 4;
} else {
}
else
{
prevMask = (prevMask << 1) | 1;
}
}

View File

@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace SharpCompress.Compressor.Filters
{
public abstract class Filter : Stream
internal abstract class Filter : Stream
{
protected bool isEncoder;
protected Stream baseStream;
@@ -22,7 +19,7 @@ namespace SharpCompress.Compressor.Filters
this.isEncoder = isEncoder;
this.baseStream = baseStream;
tail = new byte[lookahead - 1];
window = new byte[tail.Length*2];
window = new byte[tail.Length * 2];
}
public override bool CanRead
@@ -66,7 +63,7 @@ namespace SharpCompress.Compressor.Filters
{
int size = 0;
if (transformed > 0)
if (transformed > 0)
{
int copySize = transformed;
if (copySize > count)

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace SharpCompress.Compressor.LZMA
{
public class BitVector
internal class BitVector
{
private uint[] mBits;
private int mLength;
@@ -20,23 +20,23 @@ namespace SharpCompress.Compressor.LZMA
mLength = length;
mBits = new uint[(length + 31) >> 5];
if(initValue)
for(int i = 0; i < mBits.Length; i++)
if (initValue)
for (int i = 0; i < mBits.Length; i++)
mBits[i] = ~0u;
}
public BitVector(List<bool> bits)
: this(bits.Count)
{
for(int i = 0; i < bits.Count; i++)
if(bits[i])
for (int i = 0; i < bits.Count; i++)
if (bits[i])
SetBit(i);
}
public bool[] ToArray()
{
bool[] bits = new bool[mLength];
for(int i = 0; i < bits.Length; i++)
for (int i = 0; i < bits.Length; i++)
bits[i] = this[i];
return bits;
}
@@ -50,7 +50,7 @@ namespace SharpCompress.Compressor.LZMA
{
get
{
if(index < 0 || index >= mLength)
if (index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
return (mBits[index >> 5] & (1u << (index & 31))) != 0;
@@ -59,7 +59,7 @@ namespace SharpCompress.Compressor.LZMA
public void SetBit(int index)
{
if(index < 0 || index >= mLength)
if (index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
mBits[index >> 5] |= 1u << (index & 31);
@@ -67,7 +67,7 @@ namespace SharpCompress.Compressor.LZMA
internal bool GetAndSet(int index)
{
if(index < 0 || index >= mLength)
if (index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
uint bits = mBits[index >> 5];
@@ -79,7 +79,7 @@ namespace SharpCompress.Compressor.LZMA
public override string ToString()
{
StringBuilder sb = new StringBuilder(mLength);
for(int i = 0; i < mLength; i++)
for (int i = 0; i < mLength; i++)
sb.Append(this[i] ? 'x' : '.');
return sb.ToString();
}

View File

@@ -23,29 +23,29 @@ namespace SharpCompress.Compressor.LZMA
internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass, long limit)
{
switch(id.Id)
switch (id.Id)
{
case k_Copy:
if(info != null)
throw new NotSupportedException();
return inStreams.Single();
case k_LZMA:
case k_LZMA2:
return new LzmaStream(info, inStreams.Single(), -1, limit);
case k_Copy:
if (info != null)
throw new NotSupportedException();
return inStreams.Single();
case k_LZMA:
case k_LZMA2:
return new LzmaStream(info, inStreams.Single(), -1, limit);
#if !SILVERLIGHT && !PORTABLE
case CMethodId.kAESId:
return new AesDecoderStream(inStreams.Single(), info, pass, limit);
case CMethodId.kAESId:
return new AesDecoderStream(inStreams.Single(), info, pass, limit);
#endif
case k_BCJ:
return new BCJFilter(false, inStreams.Single());
case k_BCJ2:
return new Bcj2DecoderStream(inStreams, info, limit);
case k_BZip2:
return new BZip2Stream(inStreams.Single(), CompressionMode.Decompress, true);
case k_PPMD:
return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false );
default:
throw new NotSupportedException();
case k_BCJ:
return new BCJFilter(false, inStreams.Single());
case k_BCJ2:
return new Bcj2DecoderStream(inStreams, info, limit);
case k_BZip2:
return new BZip2Stream(inStreams.Single(), CompressionMode.Decompress, true);
case k_PPMD:
return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false);
default:
throw new NotSupportedException();
}
}
}

View File

@@ -1,6 +1,6 @@
namespace SharpCompress.Compressor.LZMA.Utilites
{
public interface IPasswordProvider
internal interface IPasswordProvider
{
string CryptoGetTextPassword();
}