();
- var decryptor = rijndael.CreateDecryptor();
- using (var msDecrypt = new MemoryStream(cipherText))
- {
- using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
- {
- csDecrypt.ReadFully(plainText);
- }
- }
-
- for (int j = 0; j < plainText.Length; j++)
- decryptedBytes.Add((byte)(plainText[j] ^ aesInitializationVector[j % 16])); //32:114, 33:101
-
- for (int j = 0; j < aesInitializationVector.Length; j++)
- aesInitializationVector[j] = cipherText[j];
- return decryptedBytes.ToArray();
- }
-
- public void Dispose()
- {
- ((IDisposable)rijndael).Dispose();
- }
- }
-}
diff --git a/SharpCompress/Common/Zip/WinzipAesCryptoStream.Portable.cs b/SharpCompress/Common/Zip/WinzipAesCryptoStream.Portable.cs
deleted file mode 100644
index 8611a76a..00000000
--- a/SharpCompress/Common/Zip/WinzipAesCryptoStream.Portable.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-using System;
-using System.IO;
-using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Engines;
-using Org.BouncyCastle.Crypto.Parameters;
-using SharpCompress.Converter;
-
-namespace SharpCompress.Common.Zip
-{
- internal class WinzipAesCryptoStream : Stream
- {
- private const int BLOCK_SIZE_IN_BYTES = 16;
- private readonly IBufferedCipher rijndael;
- private readonly byte[] counter = new byte[BLOCK_SIZE_IN_BYTES];
- private readonly Stream stream;
- private int nonce = 1;
- private byte[] counterOut = new byte[BLOCK_SIZE_IN_BYTES];
- private bool isFinalBlock;
- private long totalBytesLeftToRead;
- private bool isDisposed;
-
- internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
- {
- this.stream = stream;
- totalBytesLeftToRead = length;
-
- rijndael = CreateRijndael(winzipAesEncryptionData);
- }
-
- private IBufferedCipher CreateRijndael(WinzipAesEncryptionData winzipAesEncryptionData)
- {
- var blockCipher = new BufferedBlockCipher(new RijndaelEngine());
- var param = new KeyParameter(winzipAesEncryptionData.KeyBytes);
- blockCipher.Init(true, param);
- return blockCipher;
- }
-
- public override bool CanRead
- {
- get { return true; }
- }
-
- public override bool CanSeek
- {
- get { return false; }
- }
-
- public override bool CanWrite
- {
- get { return false; }
- }
-
- public override long Length
- {
- get { throw new NotImplementedException(); }
- }
-
- public override long Position
- {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
-
- protected override void Dispose(bool disposing)
- {
- if (isDisposed)
- {
- return;
- }
- isDisposed = true;
- if (disposing)
- {
- //read out last 10 auth bytes
- var ten = new byte[10];
- stream.Read(ten, 0, 10);
- stream.Dispose();
- }
- }
-
- public override void Flush()
- {
- throw new NotImplementedException();
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (totalBytesLeftToRead == 0)
- {
- return 0;
- }
- int bytesToRead = count;
- if (count > totalBytesLeftToRead)
- {
- bytesToRead = (int)totalBytesLeftToRead;
- }
- int read = stream.Read(buffer, offset, bytesToRead);
- totalBytesLeftToRead -= read;
-
- ReadTransformBlocks(buffer, offset, read);
-
- return read;
- }
-
- private int ReadTransformOneBlock(byte[] buffer, int offset, int last)
- {
- if (isFinalBlock)
- {
- throw new InvalidOperationException();
- }
-
- int bytesRemaining = last - offset;
- int bytesToRead = (bytesRemaining > BLOCK_SIZE_IN_BYTES)
- ? BLOCK_SIZE_IN_BYTES
- : bytesRemaining;
-
- // update the counter
- DataConverter.LittleEndian.PutBytes(counter, 0, nonce++);
-
- // Determine if this is the final block
- if ((bytesToRead == bytesRemaining) && (totalBytesLeftToRead == 0))
- {
- counterOut = rijndael.DoFinal(counter, 0, BLOCK_SIZE_IN_BYTES);
-
- isFinalBlock = true;
- }
- else
- {
- rijndael.ProcessBytes(counter, 0, BLOCK_SIZE_IN_BYTES, counterOut, 0);
- }
- XorInPlace(buffer, offset, bytesToRead);
- return bytesToRead;
- }
-
-
- private void XorInPlace(byte[] buffer, int offset, int count)
- {
- for (int i = 0; i < count; i++)
- {
- buffer[offset + i] = (byte)(counterOut[i] ^ buffer[offset + i]);
- }
- }
-
- private void ReadTransformBlocks(byte[] buffer, int offset, int count)
- {
- int posn = offset;
- int last = count + offset;
-
- while (posn < buffer.Length && posn < last)
- {
- int n = ReadTransformOneBlock(buffer, posn, last);
- posn += n;
- }
- }
-
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Common/Zip/WinzipAesEncryptionData.Portable.cs b/SharpCompress/Common/Zip/WinzipAesEncryptionData.Portable.cs
deleted file mode 100644
index 79a405cc..00000000
--- a/SharpCompress/Common/Zip/WinzipAesEncryptionData.Portable.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using System;
-using System.Text;
-using SharpCompress.Converter;
-using SharpCompress.Crypto;
-
-namespace SharpCompress.Common.Zip
-{
- internal class WinzipAesEncryptionData
- {
- private const int RFC2898_ITERATIONS = 1000;
-
- private byte[] salt;
- private WinzipAesKeySize keySize;
- private byte[] passwordVerifyValue;
- private string password;
-
- private byte[] generatedVerifyValue;
-
- internal WinzipAesEncryptionData(WinzipAesKeySize keySize, byte[] salt, byte[] passwordVerifyValue,
- string password)
- {
- this.keySize = keySize;
- this.salt = salt;
- this.passwordVerifyValue = passwordVerifyValue;
- this.password = password;
- Initialize();
- }
-
- internal byte[] IvBytes { get; set; }
- internal byte[] KeyBytes { get; set; }
-
- private int KeySizeInBytes
- {
- get { return KeyLengthInBytes(keySize); }
- }
-
- internal static int KeyLengthInBytes(WinzipAesKeySize keySize)
- {
- switch (keySize)
- {
- case WinzipAesKeySize.KeySize128:
- return 16;
- case WinzipAesKeySize.KeySize192:
- return 24;
- case WinzipAesKeySize.KeySize256:
- return 32;
- }
- throw new InvalidOperationException();
- }
-
- private void Initialize()
- {
- var utf8 = new UTF8Encoding(false);
- var paramz = new PBKDF2(utf8.GetBytes(password), salt, RFC2898_ITERATIONS);
- KeyBytes = paramz.GetBytes(KeySizeInBytes);
- IvBytes = paramz.GetBytes(KeySizeInBytes);
- generatedVerifyValue = paramz.GetBytes(2);
-
-
- short verify = DataConverter.LittleEndian.GetInt16(passwordVerifyValue, 0);
- if (password != null)
- {
- short generated = DataConverter.LittleEndian.GetInt16(generatedVerifyValue, 0);
- if (verify != generated)
- throw new InvalidFormatException("bad password");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Converter/DataConverter.Portable.cs b/SharpCompress/Converter/DataConverter.Portable.cs
deleted file mode 100644
index eec9846b..00000000
--- a/SharpCompress/Converter/DataConverter.Portable.cs
+++ /dev/null
@@ -1,237 +0,0 @@
-using System;
-
-namespace SharpCompress.Converter
-{
- // This is a portable version of Mono's DataConverter class with just the small subset of functionality
- // needed by SharpCompress. Portable in this case means that it contains no unsafe code.
- //
- // This class simply wraps BitConverter and reverses byte arrays when endianess doesn't match the host's.
- //
- // Everything public in this class must match signatures in Mono's DataConverter.
-
- abstract class DataConverter
- {
- static readonly DataConverter copyConverter = new CopyConverter();
- static readonly DataConverter swapConverter = new SwapConverter();
-
- static readonly bool isLittleEndian = BitConverter.IsLittleEndian;
-
- public static DataConverter LittleEndian
- {
- get { return isLittleEndian ? copyConverter : swapConverter; }
- }
-
- public static DataConverter BigEndian
- {
- get { return isLittleEndian ? swapConverter : copyConverter; }
- }
-
- public abstract Int16 GetInt16(byte[] data, int index);
- public abstract UInt16 GetUInt16(byte[] data, int index);
- public abstract Int32 GetInt32(byte[] data, int index);
- public abstract UInt32 GetUInt32(byte[] data, int index);
- public abstract Int64 GetInt64(byte[] data, int index);
- public abstract UInt64 GetUInt64(byte[] data, int index);
-
- public abstract byte[] GetBytes(Int16 value);
- public abstract byte[] GetBytes(UInt16 value);
- public abstract byte[] GetBytes(Int32 value);
- public abstract byte[] GetBytes(UInt32 value);
- public abstract byte[] GetBytes(Int64 value);
- public abstract byte[] GetBytes(UInt64 value);
-
- public void PutBytes(byte[] data, int index, Int16 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 2);
- }
-
- public void PutBytes(byte[] data, int index, UInt16 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 2);
- }
-
- public void PutBytes(byte[] data, int index, Int32 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 4);
- }
-
- public void PutBytes(byte[] data, int index, UInt32 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 4);
- }
-
- public void PutBytes(byte[] data, int index, Int64 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 8);
- }
-
- public void PutBytes(byte[] data, int index, UInt64 value)
- {
- byte[] temp = GetBytes(value);
- Array.Copy(temp, 0, data, index, 8);
- }
-
- // CopyConverter wraps BitConverter making all conversions host endian
- class CopyConverter : DataConverter
- {
- public override Int16 GetInt16(byte[] data, int index)
- {
- return BitConverter.ToInt16(data, index);
- }
-
- public override UInt16 GetUInt16(byte[] data, int index)
- {
- return BitConverter.ToUInt16(data, index);
- }
-
- public override Int32 GetInt32(byte[] data, int index)
- {
- return BitConverter.ToInt32(data, index);
- }
-
- public override UInt32 GetUInt32(byte[] data, int index)
- {
- return BitConverter.ToUInt32(data, index);
- }
-
- public override Int64 GetInt64(byte[] data, int index)
- {
- return BitConverter.ToInt64(data, index);
- }
-
- public override UInt64 GetUInt64(byte[] data, int index)
- {
- return BitConverter.ToUInt64(data, index);
- }
-
- public override byte[] GetBytes(Int16 value)
- {
- return BitConverter.GetBytes(value);
- }
-
- public override byte[] GetBytes(UInt16 value)
- {
- return BitConverter.GetBytes(value);
- }
-
- public override byte[] GetBytes(Int32 value)
- {
- return BitConverter.GetBytes(value);
- }
-
- public override byte[] GetBytes(UInt32 value)
- {
- return BitConverter.GetBytes(value);
- }
-
- public override byte[] GetBytes(Int64 value)
- {
- return BitConverter.GetBytes(value);
- }
-
- public override byte[] GetBytes(UInt64 value)
- {
- return BitConverter.GetBytes(value);
- }
- }
-
- // SwapConverter wraps and reverses BitConverter making all conversions the opposite of host endian
- class SwapConverter : DataConverter
- {
- public override Int16 GetInt16(byte[] data, int index)
- {
- byte[] temp = new byte[2];
- Array.Copy(data, index, temp, 0, 2);
- Array.Reverse(temp);
- return BitConverter.ToInt16(temp, 0);
- }
-
- public override UInt16 GetUInt16(byte[] data, int index)
- {
- byte[] temp = new byte[2];
- Array.Copy(data, index, temp, 0, 2);
- Array.Reverse(temp);
- return BitConverter.ToUInt16(temp, 0);
- }
-
- public override Int32 GetInt32(byte[] data, int index)
- {
- byte[] temp = new byte[4];
- Array.Copy(data, index, temp, 0, 4);
- Array.Reverse(temp);
- return BitConverter.ToInt32(temp, 0);
- }
-
- public override UInt32 GetUInt32(byte[] data, int index)
- {
- byte[] temp = new byte[4];
- Array.Copy(data, index, temp, 0, 4);
- Array.Reverse(temp);
- return BitConverter.ToUInt32(temp, 0);
- }
-
- public override Int64 GetInt64(byte[] data, int index)
- {
- byte[] temp = new byte[8];
- Array.Copy(data, index, temp, 0, 8);
- Array.Reverse(temp);
- return BitConverter.ToInt64(temp, 0);
- }
-
- public override UInt64 GetUInt64(byte[] data, int index)
- {
- byte[] temp = new byte[8];
- Array.Copy(data, index, temp, 0, 8);
- Array.Reverse(temp);
- return BitConverter.ToUInt64(temp, 0);
- }
-
- public override byte[] GetBytes(Int16 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
-
- public override byte[] GetBytes(UInt16 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
-
- public override byte[] GetBytes(Int32 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
-
- public override byte[] GetBytes(UInt32 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
-
- public override byte[] GetBytes(Int64 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
-
- public override byte[] GetBytes(UInt64 value)
- {
- byte[] ret = BitConverter.GetBytes(value);
- Array.Reverse(ret);
- return ret;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Crypto/BigInteger.cs b/SharpCompress/Crypto/BigInteger.cs
deleted file mode 100644
index 4cd6926d..00000000
--- a/SharpCompress/Crypto/BigInteger.cs
+++ /dev/null
@@ -1,3145 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Text;
-
-
-namespace Org.BouncyCastle.Math
-{
- public class BigInteger
- {
- // The primes b/w 2 and ~2^10
- /*
- 3 5 7 11 13 17 19 23 29
- 31 37 41 43 47 53 59 61 67 71
- 73 79 83 89 97 101 103 107 109 113
- 127 131 137 139 149 151 157 163 167 173
- 179 181 191 193 197 199 211 223 227 229
- 233 239 241 251 257 263 269 271 277 281
- 283 293 307 311 313 317 331 337 347 349
- 353 359 367 373 379 383 389 397 401 409
- 419 421 431 433 439 443 449 457 461 463
- 467 479 487 491 499 503 509 521 523 541
- 547 557 563 569 571 577 587 593 599 601
- 607 613 617 619 631 641 643 647 653 659
- 661 673 677 683 691 701 709 719 727 733
- 739 743 751 757 761 769 773 787 797 809
- 811 821 823 827 829 839 853 857 859 863
- 877 881 883 887 907 911 919 929 937 941
- 947 953 967 971 977 983 991 997
- 1009 1013 1019 1021 1031
- */
-
- // Each list has a product < 2^31
- private static readonly int[][] primeLists = new int[][]
- {
- new int[]{ 3, 5, 7, 11, 13, 17, 19, 23 },
- new int[]{ 29, 31, 37, 41, 43 },
- new int[]{ 47, 53, 59, 61, 67 },
- new int[]{ 71, 73, 79, 83 },
- new int[]{ 89, 97, 101, 103 },
-
- new int[]{ 107, 109, 113, 127 },
- new int[]{ 131, 137, 139, 149 },
- new int[]{ 151, 157, 163, 167 },
- new int[]{ 173, 179, 181, 191 },
- new int[]{ 193, 197, 199, 211 },
-
- new int[]{ 223, 227, 229 },
- new int[]{ 233, 239, 241 },
- new int[]{ 251, 257, 263 },
- new int[]{ 269, 271, 277 },
- new int[]{ 281, 283, 293 },
-
- new int[]{ 307, 311, 313 },
- new int[]{ 317, 331, 337 },
- new int[]{ 347, 349, 353 },
- new int[]{ 359, 367, 373 },
- new int[]{ 379, 383, 389 },
-
- new int[]{ 397, 401, 409 },
- new int[]{ 419, 421, 431 },
- new int[]{ 433, 439, 443 },
- new int[]{ 449, 457, 461 },
- new int[]{ 463, 467, 479 },
-
- new int[]{ 487, 491, 499 },
- new int[]{ 503, 509, 521 },
- new int[]{ 523, 541, 547 },
- new int[]{ 557, 563, 569 },
- new int[]{ 571, 577, 587 },
-
- new int[]{ 593, 599, 601 },
- new int[]{ 607, 613, 617 },
- new int[]{ 619, 631, 641 },
- new int[]{ 643, 647, 653 },
- new int[]{ 659, 661, 673 },
-
- new int[]{ 677, 683, 691 },
- new int[]{ 701, 709, 719 },
- new int[]{ 727, 733, 739 },
- new int[]{ 743, 751, 757 },
- new int[]{ 761, 769, 773 },
-
- new int[]{ 787, 797, 809 },
- new int[]{ 811, 821, 823 },
- new int[]{ 827, 829, 839 },
- new int[]{ 853, 857, 859 },
- new int[]{ 863, 877, 881 },
-
- new int[]{ 883, 887, 907 },
- new int[]{ 911, 919, 929 },
- new int[]{ 937, 941, 947 },
- new int[]{ 953, 967, 971 },
- new int[]{ 977, 983, 991 },
-
- new int[]{ 997, 1009, 1013 },
- new int[]{ 1019, 1021, 1031 },
- };
-
- private static readonly int[] primeProducts;
-
- private const long IMASK = 0xffffffffL;
- private static readonly ulong UIMASK = (ulong)IMASK;
-
- private static readonly int[] ZeroMagnitude = new int[0];
- private static readonly byte[] ZeroEncoding = new byte[0];
-
- public static readonly BigInteger Zero = new BigInteger(0, ZeroMagnitude, false);
- public static readonly BigInteger One = createUValueOf(1);
- public static readonly BigInteger Two = createUValueOf(2);
- public static readonly BigInteger Three = createUValueOf(3);
- public static readonly BigInteger Ten = createUValueOf(10);
-
- private static readonly int chunk2 = 1; // TODO Parse 64 bits at a time
- private static readonly BigInteger radix2 = ValueOf(2);
- private static readonly BigInteger radix2E = radix2.Pow(chunk2);
-
- private static readonly int chunk10 = 19;
- private static readonly BigInteger radix10 = ValueOf(10);
- private static readonly BigInteger radix10E = radix10.Pow(chunk10);
-
- private static readonly int chunk16 = 16;
- private static readonly BigInteger radix16 = ValueOf(16);
- private static readonly BigInteger radix16E = radix16.Pow(chunk16);
-
- private static readonly Random RandomSource = new Random();
-
- private const int BitsPerByte = 8;
- private const int BitsPerInt = 32;
- private const int BytesPerInt = 4;
-
- static BigInteger()
- {
- primeProducts = new int[primeLists.Length];
-
- for (int i = 0; i < primeLists.Length; ++i)
- {
- int[] primeList = primeLists[i];
- int product = 1;
- for (int j = 0; j < primeList.Length; ++j)
- {
- product *= primeList[j];
- }
- primeProducts[i] = product;
- }
- }
-
- private int sign; // -1 means -ve; +1 means +ve; 0 means 0;
- private int[] magnitude; // array of ints with [0] being the most significant
- private int nBits = -1; // cache BitCount() value
- private int nBitLength = -1; // cache calcBitLength() value
- private long mQuote = -1L; // -m^(-1) mod b, b = 2^32 (see Montgomery mult.)
-
- private static int GetByteLength(
- int nBits)
- {
- return (nBits + BitsPerByte - 1) / BitsPerByte;
- }
-
- private BigInteger()
- {
- }
-
- private BigInteger(
- int signum,
- int[] mag,
- bool checkMag)
- {
- if (checkMag)
- {
- int i = 0;
- while (i < mag.Length && mag[i] == 0)
- {
- ++i;
- }
-
- if (i == mag.Length)
- {
- // this.sign = 0;
- this.magnitude = ZeroMagnitude;
- }
- else
- {
- this.sign = signum;
-
- if (i == 0)
- {
- this.magnitude = mag;
- }
- else
- {
- // strip leading 0 words
- this.magnitude = new int[mag.Length - i];
- Array.Copy(mag, i, this.magnitude, 0, this.magnitude.Length);
- }
- }
- }
- else
- {
- this.sign = signum;
- this.magnitude = mag;
- }
- }
-
- public BigInteger(
- string value)
- : this(value, 10)
- {
- }
-
- public BigInteger(
- string str,
- int radix)
- {
- if (str.Length == 0)
- throw new FormatException("Zero length BigInteger");
-
- NumberStyles style;
- int chunk;
- BigInteger r;
- BigInteger rE;
-
- switch (radix)
- {
- case 2:
- // Is there anyway to restrict to binary digits?
- style = NumberStyles.Integer;
- chunk = chunk2;
- r = radix2;
- rE = radix2E;
- break;
- case 10:
- // This style seems to handle spaces and minus sign already (our processing redundant?)
- style = NumberStyles.Integer;
- chunk = chunk10;
- r = radix10;
- rE = radix10E;
- break;
- case 16:
- // TODO Should this be HexNumber?
- style = NumberStyles.AllowHexSpecifier;
- chunk = chunk16;
- r = radix16;
- rE = radix16E;
- break;
- default:
- throw new FormatException("Only bases 2, 10, or 16 allowed");
- }
-
-
- int index = 0;
- sign = 1;
-
- if (str[0] == '-')
- {
- if (str.Length == 1)
- throw new FormatException("Zero length BigInteger");
-
- sign = -1;
- index = 1;
- }
-
- // strip leading zeros from the string str
- while (index < str.Length && Int32.Parse(str[index].ToString(), style) == 0)
- {
- index++;
- }
-
- if (index >= str.Length)
- {
- // zero value - we're done
- sign = 0;
- magnitude = ZeroMagnitude;
- return;
- }
-
- //////
- // could we work out the max number of ints required to store
- // str.Length digits in the given base, then allocate that
- // storage in one hit?, then Generate the magnitude in one hit too?
- //////
-
- BigInteger b = Zero;
-
-
- int next = index + chunk;
-
- if (next <= str.Length)
- {
- do
- {
- string s = str.Substring(index, chunk);
- ulong i = ulong.Parse(s, style);
- BigInteger bi = createUValueOf(i);
-
- switch (radix)
- {
- case 2:
- // TODO Need this because we are parsing in radix 10 above
- if (i > 1)
- throw new FormatException("Bad character in radix 2 string: " + s);
-
- // TODO Parse 64 bits at a time
- b = b.ShiftLeft(1);
- break;
- case 16:
- b = b.ShiftLeft(64);
- break;
- default:
- b = b.Multiply(rE);
- break;
- }
-
- b = b.Add(bi);
-
- index = next;
- next += chunk;
- }
- while (next <= str.Length);
- }
-
- if (index < str.Length)
- {
- string s = str.Substring(index);
- ulong i = ulong.Parse(s, style);
- BigInteger bi = createUValueOf(i);
-
- if (b.sign > 0)
- {
- if (radix == 2)
- {
- // NB: Can't reach here since we are parsing one char at a time
- Debug.Assert(false);
-
- // TODO Parse all bits at once
- // b = b.ShiftLeft(s.Length);
- }
- else if (radix == 16)
- {
- b = b.ShiftLeft(s.Length << 2);
- }
- else
- {
- b = b.Multiply(r.Pow(s.Length));
- }
-
- b = b.Add(bi);
- }
- else
- {
- b = bi;
- }
- }
-
- // Note: This is the previous (slower) algorithm
- // while (index < value.Length)
- // {
- // char c = value[index];
- // string s = c.ToString();
- // int i = Int32.Parse(s, style);
- //
- // b = b.Multiply(r).Add(ValueOf(i));
- // index++;
- // }
-
- magnitude = b.magnitude;
- }
-
- public BigInteger(
- byte[] bytes)
- : this(bytes, 0, bytes.Length)
- {
- }
-
- public BigInteger(
- byte[] bytes,
- int offset,
- int length)
- {
- if (length == 0)
- throw new FormatException("Zero length BigInteger");
-
- // TODO Move this processing into MakeMagnitude (provide sign argument)
- if ((sbyte)bytes[offset] < 0)
- {
- this.sign = -1;
-
- int end = offset + length;
-
- int iBval;
- // strip leading sign bytes
- for (iBval = offset; iBval < end && ((sbyte)bytes[iBval] == -1); iBval++)
- {
- }
-
- if (iBval >= end)
- {
- this.magnitude = One.magnitude;
- }
- else
- {
- int numBytes = end - iBval;
- byte[] inverse = new byte[numBytes];
-
- int index = 0;
- while (index < numBytes)
- {
- inverse[index++] = (byte)~bytes[iBval++];
- }
-
- Debug.Assert(iBval == end);
-
- while (inverse[--index] == byte.MaxValue)
- {
- inverse[index] = byte.MinValue;
- }
-
- inverse[index]++;
-
- this.magnitude = MakeMagnitude(inverse, 0, inverse.Length);
- }
- }
- else
- {
- // strip leading zero bytes and return magnitude bytes
- this.magnitude = MakeMagnitude(bytes, offset, length);
- this.sign = this.magnitude.Length > 0 ? 1 : 0;
- }
- }
-
- private static int[] MakeMagnitude(
- byte[] bytes,
- int offset,
- int length)
- {
- int end = offset + length;
-
- // strip leading zeros
- int firstSignificant;
- for (firstSignificant = offset; firstSignificant < end
- && bytes[firstSignificant] == 0; firstSignificant++)
- {
- }
-
- if (firstSignificant >= end)
- {
- return ZeroMagnitude;
- }
-
- int nInts = (end - firstSignificant + 3) / BytesPerInt;
- int bCount = (end - firstSignificant) % BytesPerInt;
- if (bCount == 0)
- {
- bCount = BytesPerInt;
- }
-
- if (nInts < 1)
- {
- return ZeroMagnitude;
- }
-
- int[] mag = new int[nInts];
-
- int v = 0;
- int magnitudeIndex = 0;
- for (int i = firstSignificant; i < end; ++i)
- {
- v <<= 8;
- v |= bytes[i] & 0xff;
- bCount--;
- if (bCount <= 0)
- {
- mag[magnitudeIndex] = v;
- magnitudeIndex++;
- bCount = BytesPerInt;
- v = 0;
- }
- }
-
- if (magnitudeIndex < mag.Length)
- {
- mag[magnitudeIndex] = v;
- }
-
- return mag;
- }
-
- public BigInteger(
- int sign,
- byte[] bytes)
- : this(sign, bytes, 0, bytes.Length)
- {
- }
-
- public BigInteger(
- int sign,
- byte[] bytes,
- int offset,
- int length)
- {
- if (sign < -1 || sign > 1)
- throw new FormatException("Invalid sign value");
-
- if (sign == 0)
- {
- //this.sign = 0;
- this.magnitude = ZeroMagnitude;
- }
- else
- {
- // copy bytes
- this.magnitude = MakeMagnitude(bytes, offset, length);
- this.sign = this.magnitude.Length < 1 ? 0 : sign;
- }
- }
-
- public BigInteger(
- int sizeInBits,
- Random random)
- {
- if (sizeInBits < 0)
- throw new ArgumentException("sizeInBits must be non-negative");
-
- this.nBits = -1;
- this.nBitLength = -1;
-
- if (sizeInBits == 0)
- {
- // this.sign = 0;
- this.magnitude = ZeroMagnitude;
- return;
- }
-
- int nBytes = GetByteLength(sizeInBits);
- byte[] b = new byte[nBytes];
- random.NextBytes(b);
-
- // strip off any excess bits in the MSB
- b[0] &= rndMask[BitsPerByte * nBytes - sizeInBits];
-
- this.magnitude = MakeMagnitude(b, 0, b.Length);
- this.sign = this.magnitude.Length < 1 ? 0 : 1;
- }
-
- private static readonly byte[] rndMask = { 255, 127, 63, 31, 15, 7, 3, 1 };
-
- public BigInteger(
- int bitLength,
- int certainty,
- Random random)
- {
- if (bitLength < 2)
- throw new ArithmeticException("bitLength < 2");
-
- this.sign = 1;
- this.nBitLength = bitLength;
-
- if (bitLength == 2)
- {
- this.magnitude = random.Next(2) == 0
- ? Two.magnitude
- : Three.magnitude;
- return;
- }
-
- int nBytes = GetByteLength(bitLength);
- byte[] b = new byte[nBytes];
-
- int xBits = BitsPerByte * nBytes - bitLength;
- byte mask = rndMask[xBits];
-
- for (; ; )
- {
- random.NextBytes(b);
-
- // strip off any excess bits in the MSB
- b[0] &= mask;
-
- // ensure the leading bit is 1 (to meet the strength requirement)
- b[0] |= (byte)(1 << (7 - xBits));
-
- // ensure the trailing bit is 1 (i.e. must be odd)
- b[nBytes - 1] |= 1;
-
- this.magnitude = MakeMagnitude(b, 0, b.Length);
- this.nBits = -1;
- this.mQuote = -1L;
-
- if (certainty < 1)
- break;
-
- if (CheckProbablePrime(certainty, random))
- break;
-
- if (bitLength > 32)
- {
- for (int rep = 0; rep < 10000; ++rep)
- {
- int n = 33 + random.Next(bitLength - 2);
- this.magnitude[this.magnitude.Length - (n >> 5)] ^= (1 << (n & 31));
- this.magnitude[this.magnitude.Length - 1] ^= ((random.Next() + 1) << 1);
- this.mQuote = -1L;
-
- if (CheckProbablePrime(certainty, random))
- return;
- }
- }
- }
- }
-
- public BigInteger Abs()
- {
- return sign >= 0 ? this : Negate();
- }
-
- /**
- * return a = a + b - b preserved.
- */
- private static int[] AddMagnitudes(
- int[] a,
- int[] b)
- {
- int tI = a.Length - 1;
- int vI = b.Length - 1;
- long m = 0;
-
- while (vI >= 0)
- {
- m += ((long)(uint)a[tI] + (long)(uint)b[vI--]);
- a[tI--] = (int)m;
- m = (long)((ulong)m >> 32);
- }
-
- if (m != 0)
- {
- while (tI >= 0 && ++a[tI--] == 0)
- {
- }
- }
-
- return a;
- }
-
- public BigInteger Add(
- BigInteger value)
- {
- if (this.sign == 0)
- return value;
-
- if (this.sign != value.sign)
- {
- if (value.sign == 0)
- return this;
-
- if (value.sign < 0)
- return Subtract(value.Negate());
-
- return value.Subtract(Negate());
- }
-
- return AddToMagnitude(value.magnitude);
- }
-
- private BigInteger AddToMagnitude(
- int[] magToAdd)
- {
- int[] big, small;
- if (this.magnitude.Length < magToAdd.Length)
- {
- big = magToAdd;
- small = this.magnitude;
- }
- else
- {
- big = this.magnitude;
- small = magToAdd;
- }
-
- // Conservatively avoid over-allocation when no overflow possible
- uint limit = uint.MaxValue;
- if (big.Length == small.Length)
- limit -= (uint)small[0];
-
- bool possibleOverflow = (uint)big[0] >= limit;
-
- int[] bigCopy;
- if (possibleOverflow)
- {
- bigCopy = new int[big.Length + 1];
- big.CopyTo(bigCopy, 1);
- }
- else
- {
- bigCopy = (int[])big.Clone();
- }
-
- bigCopy = AddMagnitudes(bigCopy, small);
-
- return new BigInteger(this.sign, bigCopy, possibleOverflow);
- }
-
- public BigInteger And(
- BigInteger value)
- {
- if (this.sign == 0 || value.sign == 0)
- {
- return Zero;
- }
-
- int[] aMag = this.sign > 0
- ? this.magnitude
- : Add(One).magnitude;
-
- int[] bMag = value.sign > 0
- ? value.magnitude
- : value.Add(One).magnitude;
-
- bool resultNeg = sign < 0 && value.sign < 0;
- int resultLength = System.Math.Max(aMag.Length, bMag.Length);
- int[] resultMag = new int[resultLength];
-
- int aStart = resultMag.Length - aMag.Length;
- int bStart = resultMag.Length - bMag.Length;
-
- for (int i = 0; i < resultMag.Length; ++i)
- {
- int aWord = i >= aStart ? aMag[i - aStart] : 0;
- int bWord = i >= bStart ? bMag[i - bStart] : 0;
-
- if (this.sign < 0)
- {
- aWord = ~aWord;
- }
-
- if (value.sign < 0)
- {
- bWord = ~bWord;
- }
-
- resultMag[i] = aWord & bWord;
-
- if (resultNeg)
- {
- resultMag[i] = ~resultMag[i];
- }
- }
-
- BigInteger result = new BigInteger(1, resultMag, true);
-
- // TODO Optimise this case
- if (resultNeg)
- {
- result = result.Not();
- }
-
- return result;
- }
-
- public BigInteger AndNot(
- BigInteger val)
- {
- return And(val.Not());
- }
-
- public int BitCount
- {
- get
- {
- if (nBits == -1)
- {
- if (sign < 0)
- {
- // TODO Optimise this case
- nBits = Not().BitCount;
- }
- else
- {
- int sum = 0;
- for (int i = 0; i < magnitude.Length; i++)
- {
- sum += bitCounts[(byte)magnitude[i]];
- sum += bitCounts[(byte)(magnitude[i] >> 8)];
- sum += bitCounts[(byte)(magnitude[i] >> 16)];
- sum += bitCounts[(byte)(magnitude[i] >> 24)];
- }
- nBits = sum;
- }
- }
-
- return nBits;
- }
- }
-
- private readonly static byte[] bitCounts =
- {
- 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1,
- 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,
- 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,
- 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
- 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2,
- 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3,
- 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6,
- 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6,
- 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5,
- 6, 6, 7, 6, 7, 7, 8
- };
-
- private int calcBitLength(
- int indx,
- int[] mag)
- {
- for (; ; )
- {
- if (indx >= mag.Length)
- return 0;
-
- if (mag[indx] != 0)
- break;
-
- ++indx;
- }
-
- // bit length for everything after the first int
- int bitLength = 32 * ((mag.Length - indx) - 1);
-
- // and determine bitlength of first int
- int firstMag = mag[indx];
- bitLength += BitLen(firstMag);
-
- // Check for negative powers of two
- if (sign < 0 && ((firstMag & -firstMag) == firstMag))
- {
- do
- {
- if (++indx >= mag.Length)
- {
- --bitLength;
- break;
- }
- }
- while (mag[indx] == 0);
- }
-
- return bitLength;
- }
-
- public int BitLength
- {
- get
- {
- if (nBitLength == -1)
- {
- nBitLength = sign == 0
- ? 0
- : calcBitLength(0, magnitude);
- }
-
- return nBitLength;
- }
- }
-
- //
- // BitLen(value) is the number of bits in value.
- //
- private static int BitLen(
- int w)
- {
- // Binary search - decision tree (5 tests, rarely 6)
- return (w < 1 << 15 ? (w < 1 << 7
- ? (w < 1 << 3 ? (w < 1 << 1
- ? (w < 1 << 0 ? (w < 0 ? 32 : 0) : 1)
- : (w < 1 << 2 ? 2 : 3)) : (w < 1 << 5
- ? (w < 1 << 4 ? 4 : 5)
- : (w < 1 << 6 ? 6 : 7)))
- : (w < 1 << 11
- ? (w < 1 << 9 ? (w < 1 << 8 ? 8 : 9) : (w < 1 << 10 ? 10 : 11))
- : (w < 1 << 13 ? (w < 1 << 12 ? 12 : 13) : (w < 1 << 14 ? 14 : 15)))) : (w < 1 << 23 ? (w < 1 << 19
- ? (w < 1 << 17 ? (w < 1 << 16 ? 16 : 17) : (w < 1 << 18 ? 18 : 19))
- : (w < 1 << 21 ? (w < 1 << 20 ? 20 : 21) : (w < 1 << 22 ? 22 : 23))) : (w < 1 << 27
- ? (w < 1 << 25 ? (w < 1 << 24 ? 24 : 25) : (w < 1 << 26 ? 26 : 27))
- : (w < 1 << 29 ? (w < 1 << 28 ? 28 : 29) : (w < 1 << 30 ? 30 : 31)))));
- }
-
- // private readonly static byte[] bitLengths =
- // {
- // 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
- // 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- // 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- // 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- // 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
- // 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- // 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- // 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- // 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- // 8, 8, 8, 8, 8, 8, 8, 8
- // };
-
- private bool QuickPow2Check()
- {
- return sign > 0 && nBits == 1;
- }
-
- public int CompareTo(
- object obj)
- {
- return CompareTo((BigInteger)obj);
- }
-
- /**
- * unsigned comparison on two arrays - note the arrays may
- * start with leading zeros.
- */
- private static int CompareTo(
- int xIndx,
- int[] x,
- int yIndx,
- int[] y)
- {
- while (xIndx != x.Length && x[xIndx] == 0)
- {
- xIndx++;
- }
-
- while (yIndx != y.Length && y[yIndx] == 0)
- {
- yIndx++;
- }
-
- return CompareNoLeadingZeroes(xIndx, x, yIndx, y);
- }
-
- private static int CompareNoLeadingZeroes(
- int xIndx,
- int[] x,
- int yIndx,
- int[] y)
- {
- int diff = (x.Length - y.Length) - (xIndx - yIndx);
-
- if (diff != 0)
- {
- return diff < 0 ? -1 : 1;
- }
-
- // lengths of magnitudes the same, test the magnitude values
-
- while (xIndx < x.Length)
- {
- uint v1 = (uint)x[xIndx++];
- uint v2 = (uint)y[yIndx++];
-
- if (v1 != v2)
- return v1 < v2 ? -1 : 1;
- }
-
- return 0;
- }
-
- public int CompareTo(
- BigInteger value)
- {
- return sign < value.sign ? -1
- : sign > value.sign ? 1
- : sign == 0 ? 0
- : sign * CompareNoLeadingZeroes(0, magnitude, 0, value.magnitude);
- }
-
- /**
- * return z = x / y - done in place (z value preserved, x contains the
- * remainder)
- */
- private int[] Divide(
- int[] x,
- int[] y)
- {
- int xStart = 0;
- while (xStart < x.Length && x[xStart] == 0)
- {
- ++xStart;
- }
-
- int yStart = 0;
- while (yStart < y.Length && y[yStart] == 0)
- {
- ++yStart;
- }
-
- Debug.Assert(yStart < y.Length);
-
- int xyCmp = CompareNoLeadingZeroes(xStart, x, yStart, y);
- int[] count;
-
- if (xyCmp > 0)
- {
- int yBitLength = calcBitLength(yStart, y);
- int xBitLength = calcBitLength(xStart, x);
- int shift = xBitLength - yBitLength;
-
- int[] iCount;
- int iCountStart = 0;
-
- int[] c;
- int cStart = 0;
- int cBitLength = yBitLength;
- if (shift > 0)
- {
- // iCount = ShiftLeft(One.magnitude, shift);
- iCount = new int[(shift >> 5) + 1];
- iCount[0] = 1 << (shift % 32);
-
- c = ShiftLeft(y, shift);
- cBitLength += shift;
- }
- else
- {
- iCount = new int[] { 1 };
-
- int len = y.Length - yStart;
- c = new int[len];
- Array.Copy(y, yStart, c, 0, len);
- }
-
- count = new int[iCount.Length];
-
- for (; ; )
- {
- if (cBitLength < xBitLength
- || CompareNoLeadingZeroes(xStart, x, cStart, c) >= 0)
- {
- Subtract(xStart, x, cStart, c);
- AddMagnitudes(count, iCount);
-
- while (x[xStart] == 0)
- {
- if (++xStart == x.Length)
- return count;
- }
-
- //xBitLength = calcBitLength(xStart, x);
- xBitLength = 32 * (x.Length - xStart - 1) + BitLen(x[xStart]);
-
- if (xBitLength <= yBitLength)
- {
- if (xBitLength < yBitLength)
- return count;
-
- xyCmp = CompareNoLeadingZeroes(xStart, x, yStart, y);
-
- if (xyCmp <= 0)
- break;
- }
- }
-
- shift = cBitLength - xBitLength;
-
- // NB: The case where c[cStart] is 1-bit is harmless
- if (shift == 1)
- {
- uint firstC = (uint)c[cStart] >> 1;
- uint firstX = (uint)x[xStart];
- if (firstC > firstX)
- ++shift;
- }
-
- if (shift < 2)
- {
- ShiftRightOneInPlace(cStart, c);
- --cBitLength;
- ShiftRightOneInPlace(iCountStart, iCount);
- }
- else
- {
- ShiftRightInPlace(cStart, c, shift);
- cBitLength -= shift;
- ShiftRightInPlace(iCountStart, iCount, shift);
- }
-
- //cStart = c.Length - ((cBitLength + 31) / 32);
- while (c[cStart] == 0)
- {
- ++cStart;
- }
-
- while (iCount[iCountStart] == 0)
- {
- ++iCountStart;
- }
- }
- }
- else
- {
- count = new int[1];
- }
-
- if (xyCmp == 0)
- {
- AddMagnitudes(count, One.magnitude);
- Array.Clear(x, xStart, x.Length - xStart);
- }
-
- return count;
- }
-
- public BigInteger Divide(
- BigInteger val)
- {
- if (val.sign == 0)
- throw new ArithmeticException("Division by zero error");
-
- if (sign == 0)
- return Zero;
-
- if (val.QuickPow2Check()) // val is power of two
- {
- BigInteger result = this.Abs().ShiftRight(val.Abs().BitLength - 1);
- return val.sign == this.sign ? result : result.Negate();
- }
-
- int[] mag = (int[])this.magnitude.Clone();
-
- return new BigInteger(this.sign * val.sign, Divide(mag, val.magnitude), true);
- }
-
- public BigInteger[] DivideAndRemainder(
- BigInteger val)
- {
- if (val.sign == 0)
- throw new ArithmeticException("Division by zero error");
-
- BigInteger[] biggies = new BigInteger[2];
-
- if (sign == 0)
- {
- biggies[0] = Zero;
- biggies[1] = Zero;
- }
- else if (val.QuickPow2Check()) // val is power of two
- {
- int e = val.Abs().BitLength - 1;
- BigInteger quotient = this.Abs().ShiftRight(e);
- int[] remainder = this.LastNBits(e);
-
- biggies[0] = val.sign == this.sign ? quotient : quotient.Negate();
- biggies[1] = new BigInteger(this.sign, remainder, true);
- }
- else
- {
- int[] remainder = (int[])this.magnitude.Clone();
- int[] quotient = Divide(remainder, val.magnitude);
-
- biggies[0] = new BigInteger(this.sign * val.sign, quotient, true);
- biggies[1] = new BigInteger(this.sign, remainder, true);
- }
-
- return biggies;
- }
-
- public override bool Equals(
- object obj)
- {
- if (obj == this)
- return true;
-
- BigInteger biggie = obj as BigInteger;
- if (biggie == null)
- return false;
-
- if (biggie.sign != sign || biggie.magnitude.Length != magnitude.Length)
- return false;
-
- for (int i = 0; i < magnitude.Length; i++)
- {
- if (biggie.magnitude[i] != magnitude[i])
- {
- return false;
- }
- }
-
- return true;
- }
-
- public BigInteger Gcd(
- BigInteger value)
- {
- if (value.sign == 0)
- return Abs();
-
- if (sign == 0)
- return value.Abs();
-
- BigInteger r;
- BigInteger u = this;
- BigInteger v = value;
-
- while (v.sign != 0)
- {
- r = u.Mod(v);
- u = v;
- v = r;
- }
-
- return u;
- }
-
- public override int GetHashCode()
- {
- int hc = magnitude.Length;
- if (magnitude.Length > 0)
- {
- hc ^= magnitude[0];
-
- if (magnitude.Length > 1)
- {
- hc ^= magnitude[magnitude.Length - 1];
- }
- }
-
- return sign < 0 ? ~hc : hc;
- }
-
- // TODO Make public?
- private BigInteger Inc()
- {
- if (this.sign == 0)
- return One;
-
- if (this.sign < 0)
- return new BigInteger(-1, doSubBigLil(this.magnitude, One.magnitude), true);
-
- return AddToMagnitude(One.magnitude);
- }
-
- public int IntValue
- {
- get
- {
- return sign == 0 ? 0
- : sign > 0 ? magnitude[magnitude.Length - 1]
- : -magnitude[magnitude.Length - 1];
- }
- }
-
- /**
- * return whether or not a BigInteger is probably prime with a
- * probability of 1 - (1/2)**certainty.
- * From Knuth Vol 2, pg 395.
- */
- public bool IsProbablePrime(
- int certainty)
- {
- if (certainty <= 0)
- return true;
-
- BigInteger n = Abs();
-
- if (!n.TestBit(0))
- return n.Equals(Two);
-
- if (n.Equals(One))
- return false;
-
- return n.CheckProbablePrime(certainty, RandomSource);
- }
-
- private bool CheckProbablePrime(
- int certainty,
- Random random)
- {
- Debug.Assert(certainty > 0);
- Debug.Assert(CompareTo(Two) > 0);
- Debug.Assert(TestBit(0));
-
-
- // Try to reduce the penalty for really small numbers
- int numLists = System.Math.Min(BitLength - 1, primeLists.Length);
-
- for (int i = 0; i < numLists; ++i)
- {
- int test = Remainder(primeProducts[i]);
-
- int[] primeList = primeLists[i];
- for (int j = 0; j < primeList.Length; ++j)
- {
- int prime = primeList[j];
- int qRem = test % prime;
- if (qRem == 0)
- {
- // We may find small numbers in the list
- return BitLength < 16 && IntValue == prime;
- }
- }
- }
-
-
- // TODO Special case for < 10^16 (RabinMiller fixed list)
- // if (BitLength < 30)
- // {
- // RabinMiller against 2, 3, 5, 7, 11, 13, 23 is sufficient
- // }
-
-
- // TODO Is it worth trying to create a hybrid of these two?
- return RabinMillerTest(certainty, random);
- // return SolovayStrassenTest(certainty, random);
-
- // bool rbTest = RabinMillerTest(certainty, random);
- // bool ssTest = SolovayStrassenTest(certainty, random);
- //
- // Debug.Assert(rbTest == ssTest);
- //
- // return rbTest;
- }
-
- internal bool RabinMillerTest(
- int certainty,
- Random random)
- {
- Debug.Assert(certainty > 0);
- Debug.Assert(BitLength > 2);
- Debug.Assert(TestBit(0));
-
- // let n = 1 + d . 2^s
- BigInteger n = this;
- BigInteger nMinusOne = n.Subtract(One);
- int s = nMinusOne.GetLowestSetBit();
- BigInteger r = nMinusOne.ShiftRight(s);
-
- Debug.Assert(s >= 1);
-
- do
- {
- // TODO Make a method for random BigIntegers in range 0 < x < n)
- // - Method can be optimized by only replacing examined bits at each trial
- BigInteger a;
- do
- {
- a = new BigInteger(n.BitLength, random);
- }
- while (a.CompareTo(One) <= 0 || a.CompareTo(nMinusOne) >= 0);
-
- BigInteger y = a.ModPow(r, n);
-
- if (!y.Equals(One))
- {
- int j = 0;
- while (!y.Equals(nMinusOne))
- {
- if (++j == s)
- return false;
-
- y = y.ModPow(Two, n);
-
- if (y.Equals(One))
- return false;
- }
- }
-
- certainty -= 2; // composites pass for only 1/4 possible 'a'
- }
- while (certainty > 0);
-
- return true;
- }
-
- // private bool SolovayStrassenTest(
- // int certainty,
- // Random random)
- // {
- // Debug.Assert(certainty > 0);
- // Debug.Assert(CompareTo(Two) > 0);
- // Debug.Assert(TestBit(0));
- //
- // BigInteger n = this;
- // BigInteger nMinusOne = n.Subtract(One);
- // BigInteger e = nMinusOne.ShiftRight(1);
- //
- // do
- // {
- // BigInteger a;
- // do
- // {
- // a = new BigInteger(nBitLength, random);
- // }
- // // NB: Spec says 0 < x < n, but 1 is trivial
- // while (a.CompareTo(One) <= 0 || a.CompareTo(n) >= 0);
- //
- //
- // // TODO Check this is redundant given the way Jacobi() works?
- //// if (!a.Gcd(n).Equals(One))
- //// return false;
- //
- // int x = Jacobi(a, n);
- //
- // if (x == 0)
- // return false;
- //
- // BigInteger check = a.ModPow(e, n);
- //
- // if (x == 1 && !check.Equals(One))
- // return false;
- //
- // if (x == -1 && !check.Equals(nMinusOne))
- // return false;
- //
- // --certainty;
- // }
- // while (certainty > 0);
- //
- // return true;
- // }
- //
- // private static int Jacobi(
- // BigInteger a,
- // BigInteger b)
- // {
- // Debug.Assert(a.sign >= 0);
- // Debug.Assert(b.sign > 0);
- // Debug.Assert(b.TestBit(0));
- // Debug.Assert(a.CompareTo(b) < 0);
- //
- // int totalS = 1;
- // for (;;)
- // {
- // if (a.sign == 0)
- // return 0;
- //
- // if (a.Equals(One))
- // break;
- //
- // int e = a.GetLowestSetBit();
- //
- // int bLsw = b.magnitude[b.magnitude.Length - 1];
- // if ((e & 1) != 0 && ((bLsw & 7) == 3 || (bLsw & 7) == 5))
- // totalS = -totalS;
- //
- // // TODO Confirm this is faster than later a1.Equals(One) test
- // if (a.BitLength == e + 1)
- // break;
- // BigInteger a1 = a.ShiftRight(e);
- //// if (a1.Equals(One))
- //// break;
- //
- // int a1Lsw = a1.magnitude[a1.magnitude.Length - 1];
- // if ((bLsw & 3) == 3 && (a1Lsw & 3) == 3)
- // totalS = -totalS;
- //
- //// a = b.Mod(a1);
- // a = b.Remainder(a1);
- // b = a1;
- // }
- // return totalS;
- // }
-
- public long LongValue
- {
- get
- {
- if (sign == 0)
- return 0;
-
- long v;
- if (magnitude.Length > 1)
- {
- v = ((long)magnitude[magnitude.Length - 2] << 32)
- | (magnitude[magnitude.Length - 1] & IMASK);
- }
- else
- {
- v = (magnitude[magnitude.Length - 1] & IMASK);
- }
-
- return sign < 0 ? -v : v;
- }
- }
-
- public BigInteger Max(
- BigInteger value)
- {
- return CompareTo(value) > 0 ? this : value;
- }
-
- public BigInteger Min(
- BigInteger value)
- {
- return CompareTo(value) < 0 ? this : value;
- }
-
- public BigInteger Mod(
- BigInteger m)
- {
- if (m.sign < 1)
- throw new ArithmeticException("Modulus must be positive");
-
- BigInteger biggie = Remainder(m);
-
- return (biggie.sign >= 0 ? biggie : biggie.Add(m));
- }
-
- public BigInteger ModInverse(
- BigInteger m)
- {
- if (m.sign < 1)
- throw new ArithmeticException("Modulus must be positive");
-
- // TODO Too slow at the moment
- // // "Fast Key Exchange with Elliptic Curve Systems" R.Schoeppel
- // if (m.TestBit(0))
- // {
- // //The Almost Inverse Algorithm
- // int k = 0;
- // BigInteger B = One, C = Zero, F = this, G = m, tmp;
- //
- // for (;;)
- // {
- // // While F is even, do F=F/u, C=C*u, k=k+1.
- // int zeroes = F.GetLowestSetBit();
- // if (zeroes > 0)
- // {
- // F = F.ShiftRight(zeroes);
- // C = C.ShiftLeft(zeroes);
- // k += zeroes;
- // }
- //
- // // If F = 1, then return B,k.
- // if (F.Equals(One))
- // {
- // BigInteger half = m.Add(One).ShiftRight(1);
- // BigInteger halfK = half.ModPow(BigInteger.ValueOf(k), m);
- // return B.Multiply(halfK).Mod(m);
- // }
- //
- // if (F.CompareTo(G) < 0)
- // {
- // tmp = G; G = F; F = tmp;
- // tmp = B; B = C; C = tmp;
- // }
- //
- // F = F.Add(G);
- // B = B.Add(C);
- // }
- // }
-
- BigInteger x = new BigInteger();
- BigInteger gcd = ExtEuclid(this.Mod(m), m, x, null);
-
- if (!gcd.Equals(One))
- throw new ArithmeticException("Numbers not relatively prime.");
-
- if (x.sign < 0)
- {
- x.sign = 1;
- //x = m.Subtract(x);
- x.magnitude = doSubBigLil(m.magnitude, x.magnitude);
- }
-
- return x;
- }
-
- /**
- * Calculate the numbers u1, u2, and u3 such that:
- *
- * u1 * a + u2 * b = u3
- *
- * where u3 is the greatest common divider of a and b.
- * a and b using the extended Euclid algorithm (refer p. 323
- * of The Art of Computer Programming vol 2, 2nd ed).
- * This also seems to have the side effect of calculating
- * some form of multiplicative inverse.
- *
- * @param a First number to calculate gcd for
- * @param b Second number to calculate gcd for
- * @param u1Out the return object for the u1 value
- * @param u2Out the return object for the u2 value
- * @return The greatest common divisor of a and b
- */
- private static BigInteger ExtEuclid(
- BigInteger a,
- BigInteger b,
- BigInteger u1Out,
- BigInteger u2Out)
- {
- BigInteger u1 = One;
- BigInteger u3 = a;
- BigInteger v1 = Zero;
- BigInteger v3 = b;
-
- while (v3.sign > 0)
- {
- BigInteger[] q = u3.DivideAndRemainder(v3);
-
- BigInteger tmp = v1.Multiply(q[0]);
- BigInteger tn = u1.Subtract(tmp);
- u1 = v1;
- v1 = tn;
-
- u3 = v3;
- v3 = q[1];
- }
-
- if (u1Out != null)
- {
- u1Out.sign = u1.sign;
- u1Out.magnitude = u1.magnitude;
- }
-
- if (u2Out != null)
- {
- BigInteger tmp = u1.Multiply(a);
- tmp = u3.Subtract(tmp);
- BigInteger res = tmp.Divide(b);
- u2Out.sign = res.sign;
- u2Out.magnitude = res.magnitude;
- }
-
- return u3;
- }
-
- private static void ZeroOut(
- int[] x)
- {
- Array.Clear(x, 0, x.Length);
- }
-
- public BigInteger ModPow(
- BigInteger exponent,
- BigInteger m)
- {
- if (m.sign < 1)
- throw new ArithmeticException("Modulus must be positive");
-
- if (m.Equals(One))
- return Zero;
-
- if (exponent.sign == 0)
- return One;
-
- if (sign == 0)
- return Zero;
-
- int[] zVal = null;
- int[] yAccum = null;
- int[] yVal;
-
- // Montgomery exponentiation is only possible if the modulus is odd,
- // but AFAIK, this is always the case for crypto algo's
- bool useMonty = ((m.magnitude[m.magnitude.Length - 1] & 1) == 1);
- long mQ = 0;
- if (useMonty)
- {
- mQ = m.GetMQuote();
-
- // tmp = this * R mod m
- BigInteger tmp = ShiftLeft(32 * m.magnitude.Length).Mod(m);
- zVal = tmp.magnitude;
-
- useMonty = (zVal.Length <= m.magnitude.Length);
-
- if (useMonty)
- {
- yAccum = new int[m.magnitude.Length + 1];
- if (zVal.Length < m.magnitude.Length)
- {
- int[] longZ = new int[m.magnitude.Length];
- zVal.CopyTo(longZ, longZ.Length - zVal.Length);
- zVal = longZ;
- }
- }
- }
-
- if (!useMonty)
- {
- if (magnitude.Length <= m.magnitude.Length)
- {
- //zAccum = new int[m.magnitude.Length * 2];
- zVal = new int[m.magnitude.Length];
- magnitude.CopyTo(zVal, zVal.Length - magnitude.Length);
- }
- else
- {
- //
- // in normal practice we'll never see this...
- //
- BigInteger tmp = Remainder(m);
-
- //zAccum = new int[m.magnitude.Length * 2];
- zVal = new int[m.magnitude.Length];
- tmp.magnitude.CopyTo(zVal, zVal.Length - tmp.magnitude.Length);
- }
-
- yAccum = new int[m.magnitude.Length * 2];
- }
-
- yVal = new int[m.magnitude.Length];
-
- //
- // from LSW to MSW
- //
- for (int i = 0; i < exponent.magnitude.Length; i++)
- {
- int v = exponent.magnitude[i];
- int bits = 0;
-
- if (i == 0)
- {
- while (v > 0)
- {
- v <<= 1;
- bits++;
- }
-
- //
- // first time in initialise y
- //
- zVal.CopyTo(yVal, 0);
-
- v <<= 1;
- bits++;
- }
-
- while (v != 0)
- {
- if (useMonty)
- {
- // Montgomery square algo doesn't exist, and a normal
- // square followed by a Montgomery reduction proved to
- // be almost as heavy as a Montgomery mulitply.
- MultiplyMonty(yAccum, yVal, yVal, m.magnitude, mQ);
- }
- else
- {
- Square(yAccum, yVal);
- Remainder(yAccum, m.magnitude);
- Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0, yVal.Length);
- ZeroOut(yAccum);
- }
- bits++;
-
- if (v < 0)
- {
- if (useMonty)
- {
- MultiplyMonty(yAccum, yVal, zVal, m.magnitude, mQ);
- }
- else
- {
- Multiply(yAccum, yVal, zVal);
- Remainder(yAccum, m.magnitude);
- Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0,
- yVal.Length);
- ZeroOut(yAccum);
- }
- }
-
- v <<= 1;
- }
-
- while (bits < 32)
- {
- if (useMonty)
- {
- MultiplyMonty(yAccum, yVal, yVal, m.magnitude, mQ);
- }
- else
- {
- Square(yAccum, yVal);
- Remainder(yAccum, m.magnitude);
- Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0, yVal.Length);
- ZeroOut(yAccum);
- }
- bits++;
- }
- }
-
- if (useMonty)
- {
- // Return y * R^(-1) mod m by doing y * 1 * R^(-1) mod m
- ZeroOut(zVal);
- zVal[zVal.Length - 1] = 1;
- MultiplyMonty(yAccum, yVal, zVal, m.magnitude, mQ);
- }
-
- BigInteger result = new BigInteger(1, yVal, true);
-
- return exponent.sign > 0
- ? result
- : result.ModInverse(m);
- }
-
- /**
- * return w with w = x * x - w is assumed to have enough space.
- */
- private static int[] Square(
- int[] w,
- int[] x)
- {
- // Note: this method allows w to be only (2 * x.Length - 1) words if result will fit
- // if (w.Length != 2 * x.Length)
- // throw new ArgumentException("no I don't think so...");
-
- ulong u1, u2, c;
-
- int wBase = w.Length - 1;
-
- for (int i = x.Length - 1; i != 0; i--)
- {
- ulong v = (ulong)(uint)x[i];
-
- u1 = v * v;
- u2 = u1 >> 32;
- u1 = (uint)u1;
-
- u1 += (ulong)(uint)w[wBase];
-
- w[wBase] = (int)(uint)u1;
- c = u2 + (u1 >> 32);
-
- for (int j = i - 1; j >= 0; j--)
- {
- --wBase;
- u1 = v * (ulong)(uint)x[j];
- u2 = u1 >> 31; // multiply by 2!
- u1 = (uint)(u1 << 1); // multiply by 2!
- u1 += c + (ulong)(uint)w[wBase];
-
- w[wBase] = (int)(uint)u1;
- c = u2 + (u1 >> 32);
- }
-
- c += (ulong)(uint)w[--wBase];
- w[wBase] = (int)(uint)c;
-
- if (--wBase >= 0)
- {
- w[wBase] = (int)(uint)(c >> 32);
- }
- else
- {
- Debug.Assert((uint)(c >> 32) == 0);
- }
- wBase += i;
- }
-
- u1 = (ulong)(uint)x[0];
- u1 = u1 * u1;
- u2 = u1 >> 32;
- u1 = u1 & IMASK;
-
- u1 += (ulong)(uint)w[wBase];
-
- w[wBase] = (int)(uint)u1;
- if (--wBase >= 0)
- {
- w[wBase] = (int)(uint)(u2 + (u1 >> 32) + (ulong)(uint)w[wBase]);
- }
- else
- {
- Debug.Assert((uint)(u2 + (u1 >> 32)) == 0);
- }
-
- return w;
- }
-
- /**
- * return x with x = y * z - x is assumed to have enough space.
- */
- private static int[] Multiply(
- int[] x,
- int[] y,
- int[] z)
- {
- int i = z.Length;
-
- if (i < 1)
- return x;
-
- int xBase = x.Length - y.Length;
-
- for (; ; )
- {
- long a = z[--i] & IMASK;
- long val = 0;
-
- for (int j = y.Length - 1; j >= 0; j--)
- {
- val += a * (y[j] & IMASK) + (x[xBase + j] & IMASK);
-
- x[xBase + j] = (int)val;
-
- val = (long)((ulong)val >> 32);
- }
-
- --xBase;
-
- if (i < 1)
- {
- if (xBase >= 0)
- {
- x[xBase] = (int)val;
- }
- else
- {
- Debug.Assert(val == 0);
- }
- break;
- }
-
- x[xBase] = (int)val;
- }
-
- return x;
- }
-
- private static long FastExtEuclid(
- long a,
- long b,
- long[] uOut)
- {
- long u1 = 1;
- long u3 = a;
- long v1 = 0;
- long v3 = b;
-
- while (v3 > 0)
- {
- long q, tn;
-
- q = u3 / v3;
-
- tn = u1 - (v1 * q);
- u1 = v1;
- v1 = tn;
-
- tn = u3 - (v3 * q);
- u3 = v3;
- v3 = tn;
- }
-
- uOut[0] = u1;
- uOut[1] = (u3 - (u1 * a)) / b;
-
- return u3;
- }
-
- private static long FastModInverse(
- long v,
- long m)
- {
- if (m < 1)
- throw new ArithmeticException("Modulus must be positive");
-
- long[] x = new long[2];
- long gcd = FastExtEuclid(v, m, x);
-
- if (gcd != 1)
- throw new ArithmeticException("Numbers not relatively prime.");
-
- if (x[0] < 0)
- {
- x[0] += m;
- }
-
- return x[0];
- }
-
- // private static BigInteger MQuoteB = One.ShiftLeft(32);
- // private static BigInteger MQuoteBSub1 = MQuoteB.Subtract(One);
-
- /**
- * Calculate mQuote = -m^(-1) mod b with b = 2^32 (32 = word size)
- */
- private long GetMQuote()
- {
- Debug.Assert(this.sign > 0);
-
- if (mQuote != -1)
- {
- return mQuote; // already calculated
- }
-
- if (magnitude.Length == 0 || (magnitude[magnitude.Length - 1] & 1) == 0)
- {
- return -1; // not for even numbers
- }
-
- long v = (((~this.magnitude[this.magnitude.Length - 1]) | 1) & 0xffffffffL);
- mQuote = FastModInverse(v, 0x100000000L);
-
- return mQuote;
- }
-
- /**
- * Montgomery multiplication: a = x * y * R^(-1) mod m
- *
- * Based algorithm 14.36 of Handbook of Applied Cryptography.
- *
- * m, x, y should have length n
- * a should have length (n + 1)
- * b = 2^32, R = b^n
- *
- * The result is put in x
- *
- * NOTE: the indices of x, y, m, a different in HAC and in Java
- */
- private static void MultiplyMonty(
- int[] a,
- int[] x,
- int[] y,
- int[] m,
- long mQuote)
- // mQuote = -m^(-1) mod b
- {
- if (m.Length == 1)
- {
- x[0] = (int)MultiplyMontyNIsOne((uint)x[0], (uint)y[0], (uint)m[0], (ulong)mQuote);
- return;
- }
-
- int n = m.Length;
- int nMinus1 = n - 1;
- long y_0 = y[nMinus1] & IMASK;
-
- // 1. a = 0 (Notation: a = (a_{n} a_{n-1} ... a_{0})_{b} )
- Array.Clear(a, 0, n + 1);
-
- // 2. for i from 0 to (n - 1) do the following:
- for (int i = n; i > 0; i--)
- {
- long x_i = x[i - 1] & IMASK;
-
- // 2.1 u = ((a[0] + (x[i] * y[0]) * mQuote) mod b
- long u = ((((a[n] & IMASK) + ((x_i * y_0) & IMASK)) & IMASK) * mQuote) & IMASK;
-
- // 2.2 a = (a + x_i * y + u * m) / b
- long prod1 = x_i * y_0;
- long prod2 = u * (m[nMinus1] & IMASK);
- long tmp = (a[n] & IMASK) + (prod1 & IMASK) + (prod2 & IMASK);
- long carry = (long)((ulong)prod1 >> 32) + (long)((ulong)prod2 >> 32) + (long)((ulong)tmp >> 32);
- for (int j = nMinus1; j > 0; j--)
- {
- prod1 = x_i * (y[j - 1] & IMASK);
- prod2 = u * (m[j - 1] & IMASK);
- tmp = (a[j] & IMASK) + (prod1 & IMASK) + (prod2 & IMASK) + (carry & IMASK);
- carry = (long)((ulong)carry >> 32) + (long)((ulong)prod1 >> 32) +
- (long)((ulong)prod2 >> 32) + (long)((ulong)tmp >> 32);
- a[j + 1] = (int)tmp; // division by b
- }
- carry += (a[0] & IMASK);
- a[1] = (int)carry;
- a[0] = (int)((ulong)carry >> 32); // OJO!!!!!
- }
-
- // 3. if x >= m the x = x - m
- if (CompareTo(0, a, 0, m) >= 0)
- {
- Subtract(0, a, 0, m);
- }
-
- // put the result in x
- Array.Copy(a, 1, x, 0, n);
- }
-
- private static uint MultiplyMontyNIsOne(
- uint x,
- uint y,
- uint m,
- ulong mQuote)
- {
- ulong um = m;
- ulong prod1 = (ulong)x * (ulong)y;
- ulong u = (prod1 * mQuote) & UIMASK;
- ulong prod2 = u * um;
- ulong tmp = (prod1 & UIMASK) + (prod2 & UIMASK);
- ulong carry = (prod1 >> 32) + (prod2 >> 32) + (tmp >> 32);
-
- if (carry > um)
- {
- carry -= um;
- }
-
- return (uint)(carry & UIMASK);
- }
-
- public BigInteger Multiply(
- BigInteger val)
- {
- if (sign == 0 || val.sign == 0)
- return Zero;
-
- if (val.QuickPow2Check()) // val is power of two
- {
- BigInteger result = this.ShiftLeft(val.Abs().BitLength - 1);
- return val.sign > 0 ? result : result.Negate();
- }
-
- if (this.QuickPow2Check()) // this is power of two
- {
- BigInteger result = val.ShiftLeft(this.Abs().BitLength - 1);
- return this.sign > 0 ? result : result.Negate();
- }
-
- int resLength = (this.BitLength + val.BitLength) / BitsPerInt + 1;
- int[] res = new int[resLength];
-
- if (val == this)
- {
- Square(res, this.magnitude);
- }
- else
- {
- Multiply(res, this.magnitude, val.magnitude);
- }
-
- return new BigInteger(sign * val.sign, res, true);
- }
-
- public BigInteger Negate()
- {
- if (sign == 0)
- return this;
-
- return new BigInteger(-sign, magnitude, false);
- }
-
- public BigInteger NextProbablePrime()
- {
- if (sign < 0)
- throw new ArithmeticException("Cannot be called on value < 0");
-
- if (CompareTo(Two) < 0)
- return Two;
-
- BigInteger n = Inc().SetBit(0);
-
- while (!n.CheckProbablePrime(100, RandomSource))
- {
- n = n.Add(Two);
- }
-
- return n;
- }
-
- public BigInteger Not()
- {
- return Inc().Negate();
- }
-
- public BigInteger Pow(int exp)
- {
- if (exp < 0)
- {
- throw new ArithmeticException("Negative exponent");
- }
-
- if (exp == 0)
- {
- return One;
- }
-
- if (sign == 0 || Equals(One))
- {
- return this;
- }
-
- BigInteger y = One;
- BigInteger z = this;
-
- for (; ; )
- {
- if ((exp & 0x1) == 1)
- {
- y = y.Multiply(z);
- }
- exp >>= 1;
- if (exp == 0)
- break;
- z = z.Multiply(z);
- }
-
- return y;
- }
-
- public static BigInteger ProbablePrime(
- int bitLength,
- Random random)
- {
- return new BigInteger(bitLength, 100, random);
- }
-
- private int Remainder(
- int m)
- {
- Debug.Assert(m > 0);
-
- long acc = 0;
- for (int pos = 0; pos < magnitude.Length; ++pos)
- {
- long posVal = (uint)magnitude[pos];
- acc = (acc << 32 | posVal) % m;
- }
-
- return (int)acc;
- }
-
- /**
- * return x = x % y - done in place (y value preserved)
- */
- private int[] Remainder(
- int[] x,
- int[] y)
- {
- int xStart = 0;
- while (xStart < x.Length && x[xStart] == 0)
- {
- ++xStart;
- }
-
- int yStart = 0;
- while (yStart < y.Length && y[yStart] == 0)
- {
- ++yStart;
- }
-
- Debug.Assert(yStart < y.Length);
-
- int xyCmp = CompareNoLeadingZeroes(xStart, x, yStart, y);
-
- if (xyCmp > 0)
- {
- int yBitLength = calcBitLength(yStart, y);
- int xBitLength = calcBitLength(xStart, x);
- int shift = xBitLength - yBitLength;
-
- int[] c;
- int cStart = 0;
- int cBitLength = yBitLength;
- if (shift > 0)
- {
- c = ShiftLeft(y, shift);
- cBitLength += shift;
- Debug.Assert(c[0] != 0);
- }
- else
- {
- int len = y.Length - yStart;
- c = new int[len];
- Array.Copy(y, yStart, c, 0, len);
- }
-
- for (; ; )
- {
- if (cBitLength < xBitLength
- || CompareNoLeadingZeroes(xStart, x, cStart, c) >= 0)
- {
- Subtract(xStart, x, cStart, c);
-
- while (x[xStart] == 0)
- {
- if (++xStart == x.Length)
- return x;
- }
-
- //xBitLength = calcBitLength(xStart, x);
- xBitLength = 32 * (x.Length - xStart - 1) + BitLen(x[xStart]);
-
- if (xBitLength <= yBitLength)
- {
- if (xBitLength < yBitLength)
- return x;
-
- xyCmp = CompareNoLeadingZeroes(xStart, x, yStart, y);
-
- if (xyCmp <= 0)
- break;
- }
- }
-
- shift = cBitLength - xBitLength;
-
- // NB: The case where c[cStart] is 1-bit is harmless
- if (shift == 1)
- {
- uint firstC = (uint)c[cStart] >> 1;
- uint firstX = (uint)x[xStart];
- if (firstC > firstX)
- ++shift;
- }
-
- if (shift < 2)
- {
- ShiftRightOneInPlace(cStart, c);
- --cBitLength;
- }
- else
- {
- ShiftRightInPlace(cStart, c, shift);
- cBitLength -= shift;
- }
-
- //cStart = c.Length - ((cBitLength + 31) / 32);
- while (c[cStart] == 0)
- {
- ++cStart;
- }
- }
- }
-
- if (xyCmp == 0)
- {
- Array.Clear(x, xStart, x.Length - xStart);
- }
-
- return x;
- }
-
- public BigInteger Remainder(
- BigInteger n)
- {
- if (n.sign == 0)
- throw new ArithmeticException("Division by zero error");
-
- if (this.sign == 0)
- return Zero;
-
- // For small values, use fast remainder method
- if (n.magnitude.Length == 1)
- {
- int val = n.magnitude[0];
-
- if (val > 0)
- {
- if (val == 1)
- return Zero;
-
- // TODO Make this func work on uint, and handle val == 1?
- int rem = Remainder(val);
-
- return rem == 0
- ? Zero
- : new BigInteger(sign, new int[] { rem }, false);
- }
- }
-
- if (CompareNoLeadingZeroes(0, magnitude, 0, n.magnitude) < 0)
- return this;
-
- int[] result;
- if (n.QuickPow2Check()) // n is power of two
- {
- // TODO Move before small values branch above?
- result = LastNBits(n.Abs().BitLength - 1);
- }
- else
- {
- result = (int[])this.magnitude.Clone();
- result = Remainder(result, n.magnitude);
- }
-
- return new BigInteger(sign, result, true);
- }
-
- private int[] LastNBits(
- int n)
- {
- if (n < 1)
- return ZeroMagnitude;
-
- int numWords = (n + BitsPerInt - 1) / BitsPerInt;
- numWords = System.Math.Min(numWords, this.magnitude.Length);
- int[] result = new int[numWords];
-
- Array.Copy(this.magnitude, this.magnitude.Length - numWords, result, 0, numWords);
-
- int hiBits = n % 32;
- if (hiBits != 0)
- {
- result[0] &= ~(-1 << hiBits);
- }
-
- return result;
- }
-
- /**
- * do a left shift - this returns a new array.
- */
- private static int[] ShiftLeft(
- int[] mag,
- int n)
- {
- int nInts = (int)((uint)n >> 5);
- int nBits = n & 0x1f;
- int magLen = mag.Length;
- int[] newMag;
-
- if (nBits == 0)
- {
- newMag = new int[magLen + nInts];
- mag.CopyTo(newMag, 0);
- }
- else
- {
- int i = 0;
- int nBits2 = 32 - nBits;
- int highBits = (int)((uint)mag[0] >> nBits2);
-
- if (highBits != 0)
- {
- newMag = new int[magLen + nInts + 1];
- newMag[i++] = highBits;
- }
- else
- {
- newMag = new int[magLen + nInts];
- }
-
- int m = mag[0];
- for (int j = 0; j < magLen - 1; j++)
- {
- int next = mag[j + 1];
-
- newMag[i++] = (m << nBits) | (int)((uint)next >> nBits2);
- m = next;
- }
-
- newMag[i] = mag[magLen - 1] << nBits;
- }
-
- return newMag;
- }
-
- public BigInteger ShiftLeft(
- int n)
- {
- if (sign == 0 || magnitude.Length == 0)
- return Zero;
-
- if (n == 0)
- return this;
-
- if (n < 0)
- return ShiftRight(-n);
-
- BigInteger result = new BigInteger(sign, ShiftLeft(magnitude, n), true);
-
- if (this.nBits != -1)
- {
- result.nBits = sign > 0
- ? this.nBits
- : this.nBits + n;
- }
-
- if (this.nBitLength != -1)
- {
- result.nBitLength = this.nBitLength + n;
- }
-
- return result;
- }
-
- /**
- * do a right shift - this does it in place.
- */
- private static void ShiftRightInPlace(
- int start,
- int[] mag,
- int n)
- {
- int nInts = (int)((uint)n >> 5) + start;
- int nBits = n & 0x1f;
- int magEnd = mag.Length - 1;
-
- if (nInts != start)
- {
- int delta = (nInts - start);
-
- for (int i = magEnd; i >= nInts; i--)
- {
- mag[i] = mag[i - delta];
- }
- for (int i = nInts - 1; i >= start; i--)
- {
- mag[i] = 0;
- }
- }
-
- if (nBits != 0)
- {
- int nBits2 = 32 - nBits;
- int m = mag[magEnd];
-
- for (int i = magEnd; i > nInts; --i)
- {
- int next = mag[i - 1];
-
- mag[i] = (int)((uint)m >> nBits) | (next << nBits2);
- m = next;
- }
-
- mag[nInts] = (int)((uint)mag[nInts] >> nBits);
- }
- }
-
- /**
- * do a right shift by one - this does it in place.
- */
- private static void ShiftRightOneInPlace(
- int start,
- int[] mag)
- {
- int i = mag.Length;
- int m = mag[i - 1];
-
- while (--i > start)
- {
- int next = mag[i - 1];
- mag[i] = ((int)((uint)m >> 1)) | (next << 31);
- m = next;
- }
-
- mag[start] = (int)((uint)mag[start] >> 1);
- }
-
- public BigInteger ShiftRight(
- int n)
- {
- if (n == 0)
- return this;
-
- if (n < 0)
- return ShiftLeft(-n);
-
- if (n >= BitLength)
- return (this.sign < 0 ? One.Negate() : Zero);
-
- // int[] res = (int[]) this.magnitude.Clone();
- //
- // ShiftRightInPlace(0, res, n);
- //
- // return new BigInteger(this.sign, res, true);
-
- int resultLength = (BitLength - n + 31) >> 5;
- int[] res = new int[resultLength];
-
- int numInts = n >> 5;
- int numBits = n & 31;
-
- if (numBits == 0)
- {
- Array.Copy(this.magnitude, 0, res, 0, res.Length);
- }
- else
- {
- int numBits2 = 32 - numBits;
-
- int magPos = this.magnitude.Length - 1 - numInts;
- for (int i = resultLength - 1; i >= 0; --i)
- {
- res[i] = (int)((uint)this.magnitude[magPos--] >> numBits);
-
- if (magPos >= 0)
- {
- res[i] |= this.magnitude[magPos] << numBits2;
- }
- }
- }
-
- Debug.Assert(res[0] != 0);
-
- return new BigInteger(this.sign, res, false);
- }
-
- public int SignValue
- {
- get { return sign; }
- }
-
- /**
- * returns x = x - y - we assume x is >= y
- */
- private static int[] Subtract(
- int xStart,
- int[] x,
- int yStart,
- int[] y)
- {
- Debug.Assert(yStart < y.Length);
- Debug.Assert(x.Length - xStart >= y.Length - yStart);
-
- int iT = x.Length;
- int iV = y.Length;
- long m;
- int borrow = 0;
-
- do
- {
- m = (x[--iT] & IMASK) - (y[--iV] & IMASK) + borrow;
- x[iT] = (int)m;
-
- // borrow = (m < 0) ? -1 : 0;
- borrow = (int)(m >> 63);
- }
- while (iV > yStart);
-
- if (borrow != 0)
- {
- while (--x[--iT] == -1)
- {
- }
- }
-
- return x;
- }
-
- public BigInteger Subtract(
- BigInteger n)
- {
- if (n.sign == 0)
- return this;
-
- if (this.sign == 0)
- return n.Negate();
-
- if (this.sign != n.sign)
- return Add(n.Negate());
-
- int compare = CompareNoLeadingZeroes(0, magnitude, 0, n.magnitude);
- if (compare == 0)
- return Zero;
-
- BigInteger bigun, lilun;
- if (compare < 0)
- {
- bigun = n;
- lilun = this;
- }
- else
- {
- bigun = this;
- lilun = n;
- }
-
- return new BigInteger(this.sign * compare, doSubBigLil(bigun.magnitude, lilun.magnitude), true);
- }
-
- private static int[] doSubBigLil(
- int[] bigMag,
- int[] lilMag)
- {
- int[] res = (int[])bigMag.Clone();
-
- return Subtract(0, res, 0, lilMag);
- }
-
- public byte[] ToByteArray()
- {
- return ToByteArray(false);
- }
-
- public byte[] ToByteArrayUnsigned()
- {
- return ToByteArray(true);
- }
-
- private byte[] ToByteArray(
- bool unsigned)
- {
- if (sign == 0)
- return unsigned ? ZeroEncoding : new byte[1];
-
- int nBits = (unsigned && sign > 0)
- ? BitLength
- : BitLength + 1;
-
- int nBytes = GetByteLength(nBits);
- byte[] bytes = new byte[nBytes];
-
- int magIndex = magnitude.Length;
- int bytesIndex = bytes.Length;
-
- if (sign > 0)
- {
- while (magIndex > 1)
- {
- uint mag = (uint)magnitude[--magIndex];
- bytes[--bytesIndex] = (byte)mag;
- bytes[--bytesIndex] = (byte)(mag >> 8);
- bytes[--bytesIndex] = (byte)(mag >> 16);
- bytes[--bytesIndex] = (byte)(mag >> 24);
- }
-
- uint lastMag = (uint)magnitude[0];
- while (lastMag > byte.MaxValue)
- {
- bytes[--bytesIndex] = (byte)lastMag;
- lastMag >>= 8;
- }
-
- bytes[--bytesIndex] = (byte)lastMag;
- }
- else // sign < 0
- {
- bool carry = true;
-
- while (magIndex > 1)
- {
- uint mag = ~((uint)magnitude[--magIndex]);
-
- if (carry)
- {
- carry = (++mag == uint.MinValue);
- }
-
- bytes[--bytesIndex] = (byte)mag;
- bytes[--bytesIndex] = (byte)(mag >> 8);
- bytes[--bytesIndex] = (byte)(mag >> 16);
- bytes[--bytesIndex] = (byte)(mag >> 24);
- }
-
- uint lastMag = (uint)magnitude[0];
-
- if (carry)
- {
- // Never wraps because magnitude[0] != 0
- --lastMag;
- }
-
- while (lastMag > byte.MaxValue)
- {
- bytes[--bytesIndex] = (byte)~lastMag;
- lastMag >>= 8;
- }
-
- bytes[--bytesIndex] = (byte)~lastMag;
-
- if (bytesIndex > 0)
- {
- bytes[--bytesIndex] = byte.MaxValue;
- }
- }
-
- return bytes;
- }
-
- public override string ToString()
- {
- return ToString(10);
- }
-
- public string ToString(
- int radix)
- {
- // TODO Make this method work for other radices (ideally 2 <= radix <= 16)
-
- switch (radix)
- {
- case 2:
- case 10:
- case 16:
- break;
- default:
- throw new FormatException("Only bases 2, 10, 16 are allowed");
- }
-
- // NB: Can only happen to internally managed instances
- if (magnitude == null)
- return "null";
-
- if (sign == 0)
- return "0";
-
- Debug.Assert(magnitude.Length > 0);
-
- StringBuilder sb = new StringBuilder();
-
- if (radix == 16)
- {
- sb.Append(magnitude[0].ToString("x"));
-
- for (int i = 1; i < magnitude.Length; i++)
- {
- sb.Append(magnitude[i].ToString("x8"));
- }
- }
- else if (radix == 2)
- {
- sb.Append('1');
-
- for (int i = BitLength - 2; i >= 0; --i)
- {
- sb.Append(TestBit(i) ? '1' : '0');
- }
- }
- else
- {
- // This is algorithm 1a from chapter 4.4 in Seminumerical Algorithms, slow but it works
- var S = new List();
- BigInteger bs = ValueOf(radix);
-
- // The sign is handled separatly.
- // Notice however that for this to work, radix 16 _MUST_ be a special case,
- // unless we want to enter a recursion well. In their infinite wisdom, why did not
- // the Sun engineers made a c'tor for BigIntegers taking a BigInteger as parameter?
- // (Answer: Becuase Sun's BigIntger is clonable, something bouncycastle's isn't.)
- // BigInteger u = new BigInteger(Abs().ToString(16), 16);
- BigInteger u = this.Abs();
- BigInteger b;
-
- while (u.sign != 0)
- {
- b = u.Mod(bs);
- if (b.sign == 0)
- {
- S.Add("0");
- }
- else
- {
- // see how to interact with different bases
- S.Add(b.magnitude[0].ToString("d"));
- }
- u = u.Divide(bs);
- }
-
- // Then pop the stack
- for (int i = S.Count - 1; i >= 0; --i)
- {
- sb.Append((string)S[i]);
- }
- }
-
- string s = sb.ToString();
-
- Debug.Assert(s.Length > 0);
-
- // Strip leading zeros. (We know this number is not all zeroes though)
- if (s[0] == '0')
- {
- int nonZeroPos = 0;
- while (s[++nonZeroPos] == '0') { }
-
- s = s.Substring(nonZeroPos);
- }
-
- if (sign == -1)
- {
- s = "-" + s;
- }
-
- return s;
- }
-
- private static BigInteger createUValueOf(
- ulong value)
- {
- int msw = (int)(value >> 32);
- int lsw = (int)value;
-
- if (msw != 0)
- return new BigInteger(1, new int[] { msw, lsw }, false);
-
- if (lsw != 0)
- {
- BigInteger n = new BigInteger(1, new int[] { lsw }, false);
- // Check for a power of two
- if ((lsw & -lsw) == lsw)
- {
- n.nBits = 1;
- }
- return n;
- }
-
- return Zero;
- }
-
- private static BigInteger createValueOf(
- long value)
- {
- if (value < 0)
- {
- if (value == long.MinValue)
- return createValueOf(~value).Not();
-
- return createValueOf(-value).Negate();
- }
-
- return createUValueOf((ulong)value);
-
- // // store value into a byte array
- // byte[] b = new byte[8];
- // for (int i = 0; i < 8; i++)
- // {
- // b[7 - i] = (byte)value;
- // value >>= 8;
- // }
- //
- // return new BigInteger(b);
- }
-
- public static BigInteger ValueOf(
- long value)
- {
- switch (value)
- {
- case 0:
- return Zero;
- case 1:
- return One;
- case 2:
- return Two;
- case 3:
- return Three;
- case 10:
- return Ten;
- }
-
- return createValueOf(value);
- }
-
- public int GetLowestSetBit()
- {
- if (this.sign == 0)
- return -1;
-
- int w = magnitude.Length;
-
- while (--w > 0)
- {
- if (magnitude[w] != 0)
- break;
- }
-
- int word = (int)magnitude[w];
- Debug.Assert(word != 0);
-
- int b = (word & 0x0000FFFF) == 0
- ? (word & 0x00FF0000) == 0
- ? 7
- : 15
- : (word & 0x000000FF) == 0
- ? 23
- : 31;
-
- while (b > 0)
- {
- if ((word << b) == int.MinValue)
- break;
-
- b--;
- }
-
- return ((magnitude.Length - w) * 32 - (b + 1));
- }
-
- public bool TestBit(
- int n)
- {
- if (n < 0)
- throw new ArithmeticException("Bit position must not be negative");
-
- if (sign < 0)
- return !Not().TestBit(n);
-
- int wordNum = n / 32;
- if (wordNum >= magnitude.Length)
- return false;
-
- int word = magnitude[magnitude.Length - 1 - wordNum];
- return ((word >> (n % 32)) & 1) > 0;
- }
-
- public BigInteger Or(
- BigInteger value)
- {
- if (this.sign == 0)
- return value;
-
- if (value.sign == 0)
- return this;
-
- int[] aMag = this.sign > 0
- ? this.magnitude
- : Add(One).magnitude;
-
- int[] bMag = value.sign > 0
- ? value.magnitude
- : value.Add(One).magnitude;
-
- bool resultNeg = sign < 0 || value.sign < 0;
- int resultLength = System.Math.Max(aMag.Length, bMag.Length);
- int[] resultMag = new int[resultLength];
-
- int aStart = resultMag.Length - aMag.Length;
- int bStart = resultMag.Length - bMag.Length;
-
- for (int i = 0; i < resultMag.Length; ++i)
- {
- int aWord = i >= aStart ? aMag[i - aStart] : 0;
- int bWord = i >= bStart ? bMag[i - bStart] : 0;
-
- if (this.sign < 0)
- {
- aWord = ~aWord;
- }
-
- if (value.sign < 0)
- {
- bWord = ~bWord;
- }
-
- resultMag[i] = aWord | bWord;
-
- if (resultNeg)
- {
- resultMag[i] = ~resultMag[i];
- }
- }
-
- BigInteger result = new BigInteger(1, resultMag, true);
-
- // TODO Optimise this case
- if (resultNeg)
- {
- result = result.Not();
- }
-
- return result;
- }
-
- public BigInteger Xor(
- BigInteger value)
- {
- if (this.sign == 0)
- return value;
-
- if (value.sign == 0)
- return this;
-
- int[] aMag = this.sign > 0
- ? this.magnitude
- : Add(One).magnitude;
-
- int[] bMag = value.sign > 0
- ? value.magnitude
- : value.Add(One).magnitude;
-
- // TODO Can just replace with sign != value.sign?
- bool resultNeg = (sign < 0 && value.sign >= 0) || (sign >= 0 && value.sign < 0);
- int resultLength = System.Math.Max(aMag.Length, bMag.Length);
- int[] resultMag = new int[resultLength];
-
- int aStart = resultMag.Length - aMag.Length;
- int bStart = resultMag.Length - bMag.Length;
-
- for (int i = 0; i < resultMag.Length; ++i)
- {
- int aWord = i >= aStart ? aMag[i - aStart] : 0;
- int bWord = i >= bStart ? bMag[i - bStart] : 0;
-
- if (this.sign < 0)
- {
- aWord = ~aWord;
- }
-
- if (value.sign < 0)
- {
- bWord = ~bWord;
- }
-
- resultMag[i] = aWord ^ bWord;
-
- if (resultNeg)
- {
- resultMag[i] = ~resultMag[i];
- }
- }
-
- BigInteger result = new BigInteger(1, resultMag, true);
-
- // TODO Optimise this case
- if (resultNeg)
- {
- result = result.Not();
- }
-
- return result;
- }
-
- public BigInteger SetBit(
- int n)
- {
- if (n < 0)
- throw new ArithmeticException("Bit address less than zero");
-
- if (TestBit(n))
- return this;
-
- // TODO Handle negative values and zero
- if (sign > 0 && n < (BitLength - 1))
- return FlipExistingBit(n);
-
- return Or(One.ShiftLeft(n));
- }
-
- public BigInteger ClearBit(
- int n)
- {
- if (n < 0)
- throw new ArithmeticException("Bit address less than zero");
-
- if (!TestBit(n))
- return this;
-
- // TODO Handle negative values
- if (sign > 0 && n < (BitLength - 1))
- return FlipExistingBit(n);
-
- return AndNot(One.ShiftLeft(n));
- }
-
- public BigInteger FlipBit(
- int n)
- {
- if (n < 0)
- throw new ArithmeticException("Bit address less than zero");
-
- // TODO Handle negative values and zero
- if (sign > 0 && n < (BitLength - 1))
- return FlipExistingBit(n);
-
- return Xor(One.ShiftLeft(n));
- }
-
- private BigInteger FlipExistingBit(
- int n)
- {
- Debug.Assert(sign > 0);
- Debug.Assert(n >= 0);
- Debug.Assert(n < BitLength - 1);
-
- int[] mag = (int[])this.magnitude.Clone();
- mag[mag.Length - 1 - (n >> 5)] ^= (1 << (n & 31)); // Flip bit
- //mag[mag.Length - 1 - (n / 32)] ^= (1 << (n % 32));
- return new BigInteger(this.sign, mag, false);
- }
- }
-}
diff --git a/SharpCompress/Crypto/BufferedBlockCipher.cs b/SharpCompress/Crypto/BufferedBlockCipher.cs
deleted file mode 100644
index c7c06b3b..00000000
--- a/SharpCompress/Crypto/BufferedBlockCipher.cs
+++ /dev/null
@@ -1,376 +0,0 @@
-using System;
-
-
-namespace Org.BouncyCastle.Crypto
-{
- /**
- * A wrapper class that allows block ciphers to be used to process data in
- * a piecemeal fashion. The BufferedBlockCipher outputs a block only when the
- * buffer is full and more data is being added, or on a doFinal.
- *
- * Note: in the case where the underlying cipher is either a CFB cipher or an
- * OFB one the last block may not be a multiple of the block size.
- *
- */
- public class BufferedBlockCipher
- : BufferedCipherBase
- {
- internal byte[] buf;
- internal int bufOff;
- internal bool forEncryption;
- internal IBlockCipher cipher;
-
- /**
- * constructor for subclasses
- */
- protected BufferedBlockCipher()
- {
- }
-
- /**
- * Create a buffered block cipher without padding.
- *
- * @param cipher the underlying block cipher this buffering object wraps.
- * false otherwise.
- */
- public BufferedBlockCipher(
- IBlockCipher cipher)
- {
- if (cipher == null)
- throw new ArgumentNullException("cipher");
-
- this.cipher = cipher;
- buf = new byte[cipher.GetBlockSize()];
- bufOff = 0;
- }
-
- public override string AlgorithmName
- {
- get { return cipher.AlgorithmName; }
- }
-
- /**
- * initialise the cipher.
- *
- * @param forEncryption if true the cipher is initialised for
- * encryption, if false for decryption.
- * @param param the key and other data required by the cipher.
- * @exception ArgumentException if the parameters argument is
- * inappropriate.
- */
- // Note: This doubles as the Init in the event that this cipher is being used as an IWrapper
- public override void Init(
- bool forEncryption,
- ICipherParameters parameters)
- {
- this.forEncryption = forEncryption;
-
- //if (parameters is ParametersWithRandom)
- //{
- // parameters = ((ParametersWithRandom) parameters).Parameters;
- //}
-
- Reset();
-
- cipher.Init(forEncryption, parameters);
- }
-
- /**
- * return the blocksize for the underlying cipher.
- *
- * @return the blocksize for the underlying cipher.
- */
- public override int GetBlockSize()
- {
- return cipher.GetBlockSize();
- }
-
- /**
- * return the size of the output buffer required for an update
- * an input of len bytes.
- *
- * @param len the length of the input.
- * @return the space required to accommodate a call to update
- * with len bytes of input.
- */
- public override int GetUpdateOutputSize(
- int length)
- {
- int total = length + bufOff;
- int leftOver = total % buf.Length;
- return total - leftOver;
- }
-
- /**
- * return the size of the output buffer required for an update plus a
- * doFinal with an input of len bytes.
- *
- * @param len the length of the input.
- * @return the space required to accommodate a call to update and doFinal
- * with len bytes of input.
- */
- public override int GetOutputSize(
- int length)
- {
- // Note: Can assume IsPartialBlockOkay is true for purposes of this calculation
- return length + bufOff;
- }
-
- /**
- * process a single byte, producing an output block if neccessary.
- *
- * @param in the input byte.
- * @param out the space for any output that might be produced.
- * @param outOff the offset from which the output will be copied.
- * @return the number of output bytes copied to out.
- * @exception DataLengthException if there isn't enough space in out.
- * @exception InvalidOperationException if the cipher isn't initialised.
- */
- public override int ProcessByte(
- byte input,
- byte[] output,
- int outOff)
- {
- buf[bufOff++] = input;
-
- if (bufOff == buf.Length)
- {
- if ((outOff + buf.Length) > output.Length)
- throw new DataLengthException("output buffer too short");
-
- bufOff = 0;
- return cipher.ProcessBlock(buf, 0, output, outOff);
- }
-
- return 0;
- }
-
- public override byte[] ProcessByte(
- byte input)
- {
- int outLength = GetUpdateOutputSize(1);
-
- byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
-
- int pos = ProcessByte(input, outBytes, 0);
-
- if (outLength > 0 && pos < outLength)
- {
- byte[] tmp = new byte[pos];
- Array.Copy(outBytes, 0, tmp, 0, pos);
- outBytes = tmp;
- }
-
- return outBytes;
- }
-
- public override byte[] ProcessBytes(
- byte[] input,
- int inOff,
- int length)
- {
- if (input == null)
- throw new ArgumentNullException("input");
- if (length < 1)
- return null;
-
- int outLength = GetUpdateOutputSize(length);
-
- byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
-
- int pos = ProcessBytes(input, inOff, length, outBytes, 0);
-
- if (outLength > 0 && pos < outLength)
- {
- byte[] tmp = new byte[pos];
- Array.Copy(outBytes, 0, tmp, 0, pos);
- outBytes = tmp;
- }
-
- return outBytes;
- }
-
- /**
- * process an array of bytes, producing output if necessary.
- *
- * @param in the input byte array.
- * @param inOff the offset at which the input data starts.
- * @param len the number of bytes to be copied out of the input array.
- * @param out the space for any output that might be produced.
- * @param outOff the offset from which the output will be copied.
- * @return the number of output bytes copied to out.
- * @exception DataLengthException if there isn't enough space in out.
- * @exception InvalidOperationException if the cipher isn't initialised.
- */
- public override int ProcessBytes(
- byte[] input,
- int inOff,
- int length,
- byte[] output,
- int outOff)
- {
- if (length < 1)
- {
- if (length < 0)
- throw new ArgumentException("Can't have a negative input length!");
-
- return 0;
- }
-
- int blockSize = GetBlockSize();
- int outLength = GetUpdateOutputSize(length);
-
- if (outLength > 0)
- {
- if ((outOff + outLength) > output.Length)
- {
- throw new DataLengthException("output buffer too short");
- }
- }
-
- int resultLen = 0;
- int gapLen = buf.Length - bufOff;
- if (length > gapLen)
- {
- Array.Copy(input, inOff, buf, bufOff, gapLen);
- resultLen += cipher.ProcessBlock(buf, 0, output, outOff);
- bufOff = 0;
- length -= gapLen;
- inOff += gapLen;
- while (length > buf.Length)
- {
- resultLen += cipher.ProcessBlock(input, inOff, output, outOff + resultLen);
- length -= blockSize;
- inOff += blockSize;
- }
- }
- Array.Copy(input, inOff, buf, bufOff, length);
- bufOff += length;
- if (bufOff == buf.Length)
- {
- resultLen += cipher.ProcessBlock(buf, 0, output, outOff + resultLen);
- bufOff = 0;
- }
- return resultLen;
- }
-
- public override byte[] DoFinal()
- {
- byte[] outBytes = EmptyBuffer;
-
- int length = GetOutputSize(0);
- if (length > 0)
- {
- outBytes = new byte[length];
-
- int pos = DoFinal(outBytes, 0);
- if (pos < outBytes.Length)
- {
- byte[] tmp = new byte[pos];
- Array.Copy(outBytes, 0, tmp, 0, pos);
- outBytes = tmp;
- }
- }
- else
- {
- Reset();
- }
-
- return outBytes;
- }
-
- public override byte[] DoFinal(
- byte[] input,
- int inOff,
- int inLen)
- {
- if (input == null)
- throw new ArgumentNullException("input");
-
- int length = GetOutputSize(inLen);
-
- byte[] outBytes = EmptyBuffer;
-
- if (length > 0)
- {
- outBytes = new byte[length];
-
- int pos = (inLen > 0)
- ? ProcessBytes(input, inOff, inLen, outBytes, 0)
- : 0;
-
- pos += DoFinal(outBytes, pos);
-
- if (pos < outBytes.Length)
- {
- byte[] tmp = new byte[pos];
- Array.Copy(outBytes, 0, tmp, 0, pos);
- outBytes = tmp;
- }
- }
- else
- {
- Reset();
- }
-
- return outBytes;
- }
-
- /**
- * Process the last block in the buffer.
- *
- * @param out the array the block currently being held is copied into.
- * @param outOff the offset at which the copying starts.
- * @return the number of output bytes copied to out.
- * @exception DataLengthException if there is insufficient space in out for
- * the output, or the input is not block size aligned and should be.
- * @exception InvalidOperationException if the underlying cipher is not
- * initialised.
- * @exception InvalidCipherTextException if padding is expected and not found.
- * @exception DataLengthException if the input is not block size
- * aligned.
- */
- public override int DoFinal(
- byte[] output,
- int outOff)
- {
- try
- {
- if (bufOff != 0)
- {
- if (!cipher.IsPartialBlockOkay)
- {
- throw new DataLengthException("data not block size aligned");
- }
-
- if (outOff + bufOff > output.Length)
- {
- throw new DataLengthException("output buffer too short for DoFinal()");
- }
-
- // NB: Can't copy directly, or we may write too much output
- cipher.ProcessBlock(buf, 0, buf, 0);
- Array.Copy(buf, 0, output, outOff, bufOff);
- }
-
- return bufOff;
- }
- finally
- {
- Reset();
- }
- }
-
- /**
- * Reset the buffer and cipher. After resetting the object is in the same
- * state as it was after the last init (if there was one).
- */
- public override void Reset()
- {
- Array.Clear(buf, 0, buf.Length);
- bufOff = 0;
-
- cipher.Reset();
- }
- }
-}
diff --git a/SharpCompress/Crypto/BufferedCipherBase.cs b/SharpCompress/Crypto/BufferedCipherBase.cs
deleted file mode 100644
index f87f38c2..00000000
--- a/SharpCompress/Crypto/BufferedCipherBase.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Crypto
-{
- public abstract class BufferedCipherBase
- : IBufferedCipher
- {
- protected static readonly byte[] EmptyBuffer = new byte[0];
-
- public abstract string AlgorithmName { get; }
-
- public abstract void Init(bool forEncryption, ICipherParameters parameters);
-
- public abstract int GetBlockSize();
-
- public abstract int GetOutputSize(int inputLen);
- public abstract int GetUpdateOutputSize(int inputLen);
-
- public abstract byte[] ProcessByte(byte input);
-
- public virtual int ProcessByte(
- byte input,
- byte[] output,
- int outOff)
- {
- byte[] outBytes = ProcessByte(input);
- if (outBytes == null)
- return 0;
- if (outOff + outBytes.Length > output.Length)
- throw new DataLengthException("output buffer too short");
- outBytes.CopyTo(output, outOff);
- return outBytes.Length;
- }
-
- public virtual byte[] ProcessBytes(
- byte[] input)
- {
- return ProcessBytes(input, 0, input.Length);
- }
-
- public abstract byte[] ProcessBytes(byte[] input, int inOff, int length);
-
- public virtual int ProcessBytes(
- byte[] input,
- byte[] output,
- int outOff)
- {
- return ProcessBytes(input, 0, input.Length, output, outOff);
- }
-
- public virtual int ProcessBytes(
- byte[] input,
- int inOff,
- int length,
- byte[] output,
- int outOff)
- {
- byte[] outBytes = ProcessBytes(input, inOff, length);
- if (outBytes == null)
- return 0;
- if (outOff + outBytes.Length > output.Length)
- throw new DataLengthException("output buffer too short");
- outBytes.CopyTo(output, outOff);
- return outBytes.Length;
- }
-
- public abstract byte[] DoFinal();
-
- public virtual byte[] DoFinal(
- byte[] input)
- {
- return DoFinal(input, 0, input.Length);
- }
-
- public abstract byte[] DoFinal(
- byte[] input,
- int inOff,
- int length);
-
- public virtual int DoFinal(
- byte[] output,
- int outOff)
- {
- byte[] outBytes = DoFinal();
- if (outOff + outBytes.Length > output.Length)
- throw new DataLengthException("output buffer too short");
- outBytes.CopyTo(output, outOff);
- return outBytes.Length;
- }
-
- public virtual int DoFinal(
- byte[] input,
- byte[] output,
- int outOff)
- {
- return DoFinal(input, 0, input.Length, output, outOff);
- }
-
- public virtual int DoFinal(
- byte[] input,
- int inOff,
- int length,
- byte[] output,
- int outOff)
- {
- int len = ProcessBytes(input, inOff, length, output, outOff);
- len += DoFinal(output, outOff + len);
- return len;
- }
-
- public abstract void Reset();
- }
-}
diff --git a/SharpCompress/Crypto/GeneralDigest.cs b/SharpCompress/Crypto/GeneralDigest.cs
deleted file mode 100644
index 2c1887c8..00000000
--- a/SharpCompress/Crypto/GeneralDigest.cs
+++ /dev/null
@@ -1,115 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Crypto.Digests
-{
- public abstract class GeneralDigest
- : IDigest
- {
- private const int BYTE_LENGTH = 64;
-
- private byte[] xBuf;
- private int xBufOff;
-
- private long byteCount;
-
- internal GeneralDigest()
- {
- xBuf = new byte[4];
- }
-
- internal GeneralDigest(GeneralDigest t)
- {
- xBuf = new byte[t.xBuf.Length];
- Array.Copy(t.xBuf, 0, xBuf, 0, t.xBuf.Length);
-
- xBufOff = t.xBufOff;
- byteCount = t.byteCount;
- }
-
- public void Update(byte input)
- {
- xBuf[xBufOff++] = input;
-
- if (xBufOff == xBuf.Length)
- {
- ProcessWord(xBuf, 0);
- xBufOff = 0;
- }
-
- byteCount++;
- }
-
- public void BlockUpdate(
- byte[] input,
- int inOff,
- int length)
- {
- //
- // fill the current word
- //
- while ((xBufOff != 0) && (length > 0))
- {
- Update(input[inOff]);
- inOff++;
- length--;
- }
-
- //
- // process whole words.
- //
- while (length > xBuf.Length)
- {
- ProcessWord(input, inOff);
-
- inOff += xBuf.Length;
- length -= xBuf.Length;
- byteCount += xBuf.Length;
- }
-
- //
- // load in the remainder.
- //
- while (length > 0)
- {
- Update(input[inOff]);
-
- inOff++;
- length--;
- }
- }
-
- public void Finish()
- {
- long bitLength = (byteCount << 3);
-
- //
- // add the pad bytes.
- //
- Update((byte)128);
-
- while (xBufOff != 0)
- Update((byte)0);
- ProcessLength(bitLength);
- ProcessBlock();
- }
-
- public virtual void Reset()
- {
- byteCount = 0;
- xBufOff = 0;
- Array.Clear(xBuf, 0, xBuf.Length);
- }
-
- public int GetByteLength()
- {
- return BYTE_LENGTH;
- }
-
- internal abstract void ProcessWord(byte[] input, int inOff);
- internal abstract void ProcessLength(long bitLength);
- internal abstract void ProcessBlock();
- public abstract string AlgorithmName { get; }
- public abstract int GetDigestSize();
- public abstract int DoFinal(byte[] output, int outOff);
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Crypto/HMac.cs b/SharpCompress/Crypto/HMac.cs
deleted file mode 100644
index ecbd72f3..00000000
--- a/SharpCompress/Crypto/HMac.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-using System;
-using System.Collections;
-
-using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Parameters;
-
-namespace Org.BouncyCastle.Crypto.Macs
-{
- /**
- * HMAC implementation based on RFC2104
- *
- * H(K XOR opad, H(K XOR ipad, text))
- */
- public class HMac
- : IMac
- {
- private const byte IPAD = (byte)0x36;
- private const byte OPAD = (byte)0x5C;
-
- private readonly IDigest digest;
- private readonly int digestSize;
- private readonly int blockLength;
-
- private readonly byte[] inputPad;
- private readonly byte[] outputPad;
-
- public HMac(
- IDigest digest)
- {
- this.digest = digest;
- this.digestSize = digest.GetDigestSize();
- this.blockLength = digest.GetByteLength();
- this.inputPad = new byte[blockLength];
- this.outputPad = new byte[blockLength];
- }
-
- public string AlgorithmName
- {
- get { return digest.AlgorithmName + "/HMAC"; }
- }
-
- public IDigest GetUnderlyingDigest()
- {
- return digest;
- }
-
- public void Init(
- ICipherParameters parameters)
- {
- digest.Reset();
-
- byte[] key = ((KeyParameter)parameters).GetKey();
- int keyLength = key.Length;
-
- if (keyLength > blockLength)
- {
- digest.BlockUpdate(key, 0, key.Length);
- digest.DoFinal(inputPad, 0);
-
- keyLength = digestSize;
- }
- else
- {
- Array.Copy(key, 0, inputPad, 0, keyLength);
- }
-
- Array.Clear(inputPad, keyLength, blockLength - keyLength);
- Array.Copy(inputPad, 0, outputPad, 0, blockLength);
-
- xor(inputPad, IPAD);
- xor(outputPad, OPAD);
-
- // Initialise the digest
- digest.BlockUpdate(inputPad, 0, inputPad.Length);
- }
-
- public int GetMacSize()
- {
- return digestSize;
- }
-
- public void Update(
- byte input)
- {
- digest.Update(input);
- }
-
- public void BlockUpdate(
- byte[] input,
- int inOff,
- int len)
- {
- digest.BlockUpdate(input, inOff, len);
- }
-
- public int DoFinal(
- byte[] output,
- int outOff)
- {
- byte[] tmp = new byte[digestSize];
- digest.DoFinal(tmp, 0);
-
- digest.BlockUpdate(outputPad, 0, outputPad.Length);
- digest.BlockUpdate(tmp, 0, tmp.Length);
-
- int len = digest.DoFinal(output, outOff);
-
- // Initialise the digest
- digest.BlockUpdate(inputPad, 0, inputPad.Length);
-
- return len;
- }
-
- /**
- * Reset the mac generator.
- */
- public void Reset()
- {
- // Reset underlying digest
- digest.Reset();
-
- // Initialise the digest
- digest.BlockUpdate(inputPad, 0, inputPad.Length);
- }
-
- private static void xor(byte[] a, byte n)
- {
- for (int i = 0; i < a.Length; ++i)
- {
- a[i] ^= n;
- }
- }
- }
-}
diff --git a/SharpCompress/Crypto/IBufferedCipher.cs b/SharpCompress/Crypto/IBufferedCipher.cs
deleted file mode 100644
index 207b9f09..00000000
--- a/SharpCompress/Crypto/IBufferedCipher.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Crypto
-{
- /// Block cipher engines are expected to conform to this interface.
- public interface IBufferedCipher
- {
- /// The name of the algorithm this cipher implements.
- string AlgorithmName { get; }
-
- /// Initialise the cipher.
- /// If true the cipher is initialised for encryption,
- /// if false for decryption.
- /// The key and other data required by the cipher.
- void Init(bool forEncryption, ICipherParameters parameters);
-
- int GetBlockSize();
-
- int GetOutputSize(int inputLen);
-
- int GetUpdateOutputSize(int inputLen);
-
- byte[] ProcessByte(byte input);
- int ProcessByte(byte input, byte[] output, int outOff);
-
- byte[] ProcessBytes(byte[] input);
- byte[] ProcessBytes(byte[] input, int inOff, int length);
- int ProcessBytes(byte[] input, byte[] output, int outOff);
- int ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff);
-
- byte[] DoFinal();
- byte[] DoFinal(byte[] input);
- byte[] DoFinal(byte[] input, int inOff, int length);
- int DoFinal(byte[] output, int outOff);
- int DoFinal(byte[] input, byte[] output, int outOff);
- int DoFinal(byte[] input, int inOff, int length, byte[] output, int outOff);
-
- ///
- /// Reset the cipher. After resetting the cipher is in the same state
- /// as it was after the last init (if there was one).
- ///
- void Reset();
- }
-}
diff --git a/SharpCompress/Crypto/IDigest.cs b/SharpCompress/Crypto/IDigest.cs
deleted file mode 100644
index 9b2bfffb..00000000
--- a/SharpCompress/Crypto/IDigest.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-namespace Org.BouncyCastle.Crypto
-{
- public interface IDigest
- {
- /**
- * return the algorithm name
- *
- * @return the algorithm name
- */
- string AlgorithmName { get; }
-
- /**
- * return the size, in bytes, of the digest produced by this message digest.
- *
- * @return the size, in bytes, of the digest produced by this message digest.
- */
- int GetDigestSize();
-
- /**
- * return the size, in bytes, of the internal buffer used by this digest.
- *
- * @return the size, in bytes, of the internal buffer used by this digest.
- */
- int GetByteLength();
-
- /**
- * update the message digest with a single byte.
- *
- * @param inByte the input byte to be entered.
- */
- void Update(byte input);
-
- /**
- * update the message digest with a block of bytes.
- *
- * @param input the byte array containing the data.
- * @param inOff the offset into the byte array where the data starts.
- * @param len the length of the data.
- */
- void BlockUpdate(byte[] input, int inOff, int length);
-
- /**
- * Close the digest, producing the final digest value. The doFinal
- * call leaves the digest reset.
- *
- * @param output the array the digest is to be copied into.
- * @param outOff the offset into the out array the digest is to start at.
- */
- int DoFinal(byte[] output, int outOff);
-
- /**
- * reset the digest back to it's initial state.
- */
- void Reset();
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Crypto/IMac.cs b/SharpCompress/Crypto/IMac.cs
deleted file mode 100644
index 4305d6b0..00000000
--- a/SharpCompress/Crypto/IMac.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-namespace Org.BouncyCastle.Crypto
-{
- public interface IMac
- {
- /**
- * Initialise the MAC.
- *
- * @param param the key and other data required by the MAC.
- * @exception ArgumentException if the parameters argument is
- * inappropriate.
- */
- void Init(ICipherParameters parameters);
-
- /**
- * Return the name of the algorithm the MAC implements.
- *
- * @return the name of the algorithm the MAC implements.
- */
- string AlgorithmName { get; }
-
- /**
- * Return the block size for this MAC (in bytes).
- *
- * @return the block size for this MAC in bytes.
- */
- int GetMacSize();
-
- /**
- * add a single byte to the mac for processing.
- *
- * @param in the byte to be processed.
- * @exception InvalidOperationException if the MAC is not initialised.
- */
- void Update(byte input);
-
- /**
- * @param in the array containing the input.
- * @param inOff the index in the array the data begins at.
- * @param len the length of the input starting at inOff.
- * @exception InvalidOperationException if the MAC is not initialised.
- * @exception DataLengthException if there isn't enough data in in.
- */
- void BlockUpdate(byte[] input, int inOff, int len);
-
- /**
- * Compute the final stage of the MAC writing the output to the out
- * parameter.
- *
- * doFinal leaves the MAC in the same state it was after the last init.
- *
- * @param out the array the MAC is to be output to.
- * @param outOff the offset into the out buffer the output is to start at.
- * @exception DataLengthException if there isn't enough space in out.
- * @exception InvalidOperationException if the MAC is not initialised.
- */
- int DoFinal(byte[] output, int outOff);
-
- /**
- * Reset the MAC. At the end of resetting the MAC should be in the
- * in the same state it was after the last init (if there was one).
- */
- void Reset();
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Crypto/PBKDF2.cs b/SharpCompress/Crypto/PBKDF2.cs
deleted file mode 100644
index ae7f2c99..00000000
--- a/SharpCompress/Crypto/PBKDF2.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-using System;
-using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Digests;
-using Org.BouncyCastle.Crypto.Macs;
-using Org.BouncyCastle.Crypto.Parameters;
-using SharpCompress.Converter;
-
-namespace SharpCompress.Crypto
-{
- //Gathered from:
- //http://stackoverflow.com/questions/3210795/pbkdf2-in-bouncy-castle-c-sharp and Rfc2898DeriveBytes
- internal class PBKDF2
- {
- private readonly IMac hMac = new HMac(new Sha1Digest());
- private readonly byte[] state = new byte[20];
- private int endIndex;
- private int startIndex;
- private uint block = 1u;
- private readonly byte[] password;
- private readonly byte[] salt;
- private readonly int iterations;
-
-
- public PBKDF2(byte[] password, byte[] salt, int iterations)
- {
- this.password = password;
- this.salt = salt;
- this.iterations = iterations;
- }
-
- public byte[] GetBytes(int cb)
- {
- if (cb <= 0)
- {
- throw new ArgumentOutOfRangeException("cb");
- }
- byte[] array = new byte[cb];
- int i = 0;
- int num = endIndex - startIndex;
- if (num > 0)
- {
- if (cb < num)
- {
- Buffer.BlockCopy(state, startIndex, array, 0, cb);
- startIndex += cb;
- return array;
- }
- Buffer.BlockCopy(state, startIndex, array, 0, num);
- startIndex = (endIndex = 0);
- i += num;
- }
- while (i < cb)
- {
- byte[] src = Hash();
- int num2 = cb - i;
- if (num2 <= 20)
- {
- Buffer.BlockCopy(src, 0, array, i, num2);
- i += num2;
- Buffer.BlockCopy(src, num2, state, startIndex, 20 - num2);
- endIndex += 20 - num2;
- return array;
- }
- Buffer.BlockCopy(src, 0, array, i, 20);
- i += 20;
- }
- return array;
- }
-
- private byte[] Hash()
- {
- byte[] array = DataConverter.BigEndian.GetBytes(block);
- ICipherParameters param = new KeyParameter(password);
-
- hMac.Init(param);
- hMac.BlockUpdate(salt, 0, salt.Length);
-
- hMac.BlockUpdate(array, 0, array.Length);
- byte[] array2 = new byte[20];
- hMac.DoFinal(array2, 0);
-
- hMac.Init(param);
-
- byte[] array3 = new byte[20];
- Buffer.BlockCopy(array2, 0, array3, 0, 20);
- int num = 2;
- while (num <= (long)((ulong)iterations))
- {
- hMac.BlockUpdate(array2, 0, array2.Length);
- hMac.DoFinal(array2, 0);
- for (int i = 0; i < 20; i++)
- {
- array3[i] ^= array2[i];
- }
- num++;
- }
- block += 1u;
- return array3;
- }
- }
-}
-
diff --git a/SharpCompress/Crypto/Pack.cs b/SharpCompress/Crypto/Pack.cs
deleted file mode 100644
index 6bc20995..00000000
--- a/SharpCompress/Crypto/Pack.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-namespace Org.BouncyCastle.Crypto.Utilities
-{
- internal sealed class Pack
- {
- private Pack()
- {
- }
-
- internal static void UInt32_To_BE(uint n, byte[] bs)
- {
- bs[0] = (byte)(n >> 24);
- bs[1] = (byte)(n >> 16);
- bs[2] = (byte)(n >> 8);
- bs[3] = (byte)(n);
- }
-
- internal static void UInt32_To_BE(uint n, byte[] bs, int off)
- {
- bs[off] = (byte)(n >> 24);
- bs[++off] = (byte)(n >> 16);
- bs[++off] = (byte)(n >> 8);
- bs[++off] = (byte)(n);
- }
-
- internal static uint BE_To_UInt32(byte[] bs)
- {
- uint n = (uint)bs[0] << 24;
- n |= (uint)bs[1] << 16;
- n |= (uint)bs[2] << 8;
- n |= (uint)bs[3];
- return n;
- }
-
- internal static uint BE_To_UInt32(byte[] bs, int off)
- {
- uint n = (uint)bs[off] << 24;
- n |= (uint)bs[++off] << 16;
- n |= (uint)bs[++off] << 8;
- n |= (uint)bs[++off];
- return n;
- }
-
- internal static ulong BE_To_UInt64(byte[] bs)
- {
- uint hi = BE_To_UInt32(bs);
- uint lo = BE_To_UInt32(bs, 4);
- return ((ulong)hi << 32) | (ulong)lo;
- }
-
- internal static ulong BE_To_UInt64(byte[] bs, int off)
- {
- uint hi = BE_To_UInt32(bs, off);
- uint lo = BE_To_UInt32(bs, off + 4);
- return ((ulong)hi << 32) | (ulong)lo;
- }
-
- internal static void UInt64_To_BE(ulong n, byte[] bs)
- {
- UInt32_To_BE((uint)(n >> 32), bs);
- UInt32_To_BE((uint)(n), bs, 4);
- }
-
- internal static void UInt64_To_BE(ulong n, byte[] bs, int off)
- {
- UInt32_To_BE((uint)(n >> 32), bs, off);
- UInt32_To_BE((uint)(n), bs, off + 4);
- }
-
- internal static void UInt32_To_LE(uint n, byte[] bs)
- {
- bs[0] = (byte)(n);
- bs[1] = (byte)(n >> 8);
- bs[2] = (byte)(n >> 16);
- bs[3] = (byte)(n >> 24);
- }
-
- internal static void UInt32_To_LE(uint n, byte[] bs, int off)
- {
- bs[off] = (byte)(n);
- bs[++off] = (byte)(n >> 8);
- bs[++off] = (byte)(n >> 16);
- bs[++off] = (byte)(n >> 24);
- }
-
- internal static uint LE_To_UInt32(byte[] bs)
- {
- uint n = (uint)bs[0];
- n |= (uint)bs[1] << 8;
- n |= (uint)bs[2] << 16;
- n |= (uint)bs[3] << 24;
- return n;
- }
-
- internal static uint LE_To_UInt32(byte[] bs, int off)
- {
- uint n = (uint)bs[off];
- n |= (uint)bs[++off] << 8;
- n |= (uint)bs[++off] << 16;
- n |= (uint)bs[++off] << 24;
- return n;
- }
-
- internal static ulong LE_To_UInt64(byte[] bs)
- {
- uint lo = LE_To_UInt32(bs);
- uint hi = LE_To_UInt32(bs, 4);
- return ((ulong)hi << 32) | (ulong)lo;
- }
-
- internal static ulong LE_To_UInt64(byte[] bs, int off)
- {
- uint lo = LE_To_UInt32(bs, off);
- uint hi = LE_To_UInt32(bs, off + 4);
- return ((ulong)hi << 32) | (ulong)lo;
- }
-
- internal static void UInt64_To_LE(ulong n, byte[] bs)
- {
- UInt32_To_LE((uint)(n), bs);
- UInt32_To_LE((uint)(n >> 32), bs, 4);
- }
-
- internal static void UInt64_To_LE(ulong n, byte[] bs, int off)
- {
- UInt32_To_LE((uint)(n), bs, off);
- UInt32_To_LE((uint)(n >> 32), bs, off + 4);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/Crypto/Sha1Digest.cs b/SharpCompress/Crypto/Sha1Digest.cs
deleted file mode 100644
index 8732e040..00000000
--- a/SharpCompress/Crypto/Sha1Digest.cs
+++ /dev/null
@@ -1,255 +0,0 @@
-using System;
-using Org.BouncyCastle.Crypto.Utilities;
-
-namespace Org.BouncyCastle.Crypto.Digests
-{
- public class Sha1Digest
- : GeneralDigest
- {
- private const int DigestLength = 20;
-
- private uint H1, H2, H3, H4, H5;
-
- private uint[] X = new uint[80];
- private int xOff;
-
- public Sha1Digest()
- {
- Reset();
- }
-
- /**
- * Copy constructor. This will copy the state of the provided
- * message digest.
- */
- public Sha1Digest(Sha1Digest t)
- : base(t)
- {
- H1 = t.H1;
- H2 = t.H2;
- H3 = t.H3;
- H4 = t.H4;
- H5 = t.H5;
-
- Array.Copy(t.X, 0, X, 0, t.X.Length);
- xOff = t.xOff;
- }
-
- public override string AlgorithmName
- {
- get { return "SHA-1"; }
- }
-
- public override int GetDigestSize()
- {
- return DigestLength;
- }
-
- internal override void ProcessWord(
- byte[] input,
- int inOff)
- {
- X[xOff] = Pack.BE_To_UInt32(input, inOff);
-
- if (++xOff == 16)
- {
- ProcessBlock();
- }
- }
-
- internal override void ProcessLength(long bitLength)
- {
- if (xOff > 14)
- {
- ProcessBlock();
- }
-
- X[14] = (uint)((ulong)bitLength >> 32);
- X[15] = (uint)((ulong)bitLength);
- }
-
- public override int DoFinal(
- byte[] output,
- int outOff)
- {
- Finish();
-
- Pack.UInt32_To_BE(H1, output, outOff);
- Pack.UInt32_To_BE(H2, output, outOff + 4);
- Pack.UInt32_To_BE(H3, output, outOff + 8);
- Pack.UInt32_To_BE(H4, output, outOff + 12);
- Pack.UInt32_To_BE(H5, output, outOff + 16);
-
- Reset();
-
- return DigestLength;
- }
-
- /**
- * reset the chaining variables
- */
- public override void Reset()
- {
- base.Reset();
-
- H1 = 0x67452301;
- H2 = 0xefcdab89;
- H3 = 0x98badcfe;
- H4 = 0x10325476;
- H5 = 0xc3d2e1f0;
-
- xOff = 0;
- Array.Clear(X, 0, X.Length);
- }
-
- //
- // Additive constants
- //
- private const uint Y1 = 0x5a827999;
- private const uint Y2 = 0x6ed9eba1;
- private const uint Y3 = 0x8f1bbcdc;
- private const uint Y4 = 0xca62c1d6;
-
- private static uint F(uint u, uint v, uint w)
- {
- return (u & v) | (~u & w);
- }
-
- private static uint H(uint u, uint v, uint w)
- {
- return u ^ v ^ w;
- }
-
- private static uint G(uint u, uint v, uint w)
- {
- return (u & v) | (u & w) | (v & w);
- }
-
- internal override void ProcessBlock()
- {
- //
- // expand 16 word block into 80 word block.
- //
- for (int i = 16; i < 80; i++)
- {
- uint t = X[i - 3] ^ X[i - 8] ^ X[i - 14] ^ X[i - 16];
- X[i] = t << 1 | t >> 31;
- }
-
- //
- // set up working variables.
- //
- uint A = H1;
- uint B = H2;
- uint C = H3;
- uint D = H4;
- uint E = H5;
-
- //
- // round 1
- //
- int idx = 0;
-
- for (int j = 0; j < 4; j++)
- {
- // E = rotateLeft(A, 5) + F(B, C, D) + E + X[idx++] + Y1
- // B = rotateLeft(B, 30)
- E += (A << 5 | (A >> 27)) + F(B, C, D) + X[idx++] + Y1;
- B = B << 30 | (B >> 2);
-
- D += (E << 5 | (E >> 27)) + F(A, B, C) + X[idx++] + Y1;
- A = A << 30 | (A >> 2);
-
- C += (D << 5 | (D >> 27)) + F(E, A, B) + X[idx++] + Y1;
- E = E << 30 | (E >> 2);
-
- B += (C << 5 | (C >> 27)) + F(D, E, A) + X[idx++] + Y1;
- D = D << 30 | (D >> 2);
-
- A += (B << 5 | (B >> 27)) + F(C, D, E) + X[idx++] + Y1;
- C = C << 30 | (C >> 2);
- }
-
- //
- // round 2
- //
- for (int j = 0; j < 4; j++)
- {
- // E = rotateLeft(A, 5) + H(B, C, D) + E + X[idx++] + Y2
- // B = rotateLeft(B, 30)
- E += (A << 5 | (A >> 27)) + H(B, C, D) + X[idx++] + Y2;
- B = B << 30 | (B >> 2);
-
- D += (E << 5 | (E >> 27)) + H(A, B, C) + X[idx++] + Y2;
- A = A << 30 | (A >> 2);
-
- C += (D << 5 | (D >> 27)) + H(E, A, B) + X[idx++] + Y2;
- E = E << 30 | (E >> 2);
-
- B += (C << 5 | (C >> 27)) + H(D, E, A) + X[idx++] + Y2;
- D = D << 30 | (D >> 2);
-
- A += (B << 5 | (B >> 27)) + H(C, D, E) + X[idx++] + Y2;
- C = C << 30 | (C >> 2);
- }
-
- //
- // round 3
- //
- for (int j = 0; j < 4; j++)
- {
- // E = rotateLeft(A, 5) + G(B, C, D) + E + X[idx++] + Y3
- // B = rotateLeft(B, 30)
- E += (A << 5 | (A >> 27)) + G(B, C, D) + X[idx++] + Y3;
- B = B << 30 | (B >> 2);
-
- D += (E << 5 | (E >> 27)) + G(A, B, C) + X[idx++] + Y3;
- A = A << 30 | (A >> 2);
-
- C += (D << 5 | (D >> 27)) + G(E, A, B) + X[idx++] + Y3;
- E = E << 30 | (E >> 2);
-
- B += (C << 5 | (C >> 27)) + G(D, E, A) + X[idx++] + Y3;
- D = D << 30 | (D >> 2);
-
- A += (B << 5 | (B >> 27)) + G(C, D, E) + X[idx++] + Y3;
- C = C << 30 | (C >> 2);
- }
-
- //
- // round 4
- //
- for (int j = 0; j < 4; j++)
- {
- // E = rotateLeft(A, 5) + H(B, C, D) + E + X[idx++] + Y4
- // B = rotateLeft(B, 30)
- E += (A << 5 | (A >> 27)) + H(B, C, D) + X[idx++] + Y4;
- B = B << 30 | (B >> 2);
-
- D += (E << 5 | (E >> 27)) + H(A, B, C) + X[idx++] + Y4;
- A = A << 30 | (A >> 2);
-
- C += (D << 5 | (D >> 27)) + H(E, A, B) + X[idx++] + Y4;
- E = E << 30 | (E >> 2);
-
- B += (C << 5 | (C >> 27)) + H(D, E, A) + X[idx++] + Y4;
- D = D << 30 | (D >> 2);
-
- A += (B << 5 | (B >> 27)) + H(C, D, E) + X[idx++] + Y4;
- C = C << 30 | (C >> 2);
- }
-
- H1 += A;
- H2 += B;
- H3 += C;
- H4 += D;
- H5 += E;
-
- //
- // reset start of the buffer.
- //
- xOff = 0;
- Array.Clear(X, 0, 16);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpCompress/SharpCompress.Portable.csproj b/SharpCompress/SharpCompress.Portable.csproj
deleted file mode 100644
index bd7fe06b..00000000
--- a/SharpCompress/SharpCompress.Portable.csproj
+++ /dev/null
@@ -1,340 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {7FA7D133-1417-4F85-9998-4C618AC8FEDA}
- Library
- Properties
- SharpCompress
- SharpCompress
- v4.0
- Profile136
- 512
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- ..\..\sharpcompress\
- obj\Portable\
- true
- 10.0
-
-
-
-
- 4.0
-
-
- true
- full
- false
- ..\bin\Portable\
- TRACE;DEBUG;PORTABLE
- prompt
- 4
- true
-
-
- pdbonly
- true
- ..\bin\Portable\
- TRACE;PORTABLE
- prompt
- 4
- true
-
-
- true
-
-
- SharpCompress.pfx
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpCompress/SharpCompress.PortableTest.csproj b/SharpCompress/SharpCompress.PortableTest.csproj
deleted file mode 100644
index 10132b56..00000000
--- a/SharpCompress/SharpCompress.PortableTest.csproj
+++ /dev/null
@@ -1,409 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {EFDCAF57-FD4D-4E5D-A3D5-F26B875817ED}
- Library
- Properties
- SharpCompress
- SharpCompress.PortableTest
- v4.0
- 512
-
-
-
-
- 3.5
-
- publish\
- true
- Disk
- false
- Foreground
- 7
- Days
- false
- false
- true
- 0
- 1.0.0.%2a
- false
- false
- true
- Client
-
-
-
-
-
-
-
-
- ..\..\sharpcompress\
- true
-
-
- true
- full
- false
- ..\bin\
- TRACE;DEBUG;DISABLE_TRACE;UNSIGNED
- prompt
- 4
- true
- true
- AllRules.ruleset
- 1591
- ..\bin\SharpCompress.PortableTest.xml
-
-
- pdbonly
- true
- ..\bin\
- TRACE;UNSIGNED
- prompt
- 4
- true
- AllRules.ruleset
- ..\bin\SharpCompress.PortableTest.xml
- 1591
- true
-
-
- false
-
-
- SharpCompress.pfx
-
-
-
-
- 3.5
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
- Code
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
- .NET Framework 3.5 SP1 Client Profile
- false
-
-
- False
- .NET Framework 3.5 SP1
- true
-
-
- False
- Windows Installer 3.1
- true
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpCompress/SharpCompress.Unsigned.csproj b/SharpCompress/SharpCompress.Unsigned.csproj
deleted file mode 100644
index 7f41cc55..00000000
--- a/SharpCompress/SharpCompress.Unsigned.csproj
+++ /dev/null
@@ -1,397 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {27D535CB-2FD3-4621-8C9A-46161FC77A5D}
- Library
- Properties
- SharpCompress
- SharpCompress.Unsigned
- v4.0
- 512
-
-
-
-
- 3.5
-
- publish\
- true
- Disk
- false
- Foreground
- 7
- Days
- false
- false
- true
- 0
- 1.0.0.%2a
- false
- false
- true
- Client
- obj\Full\
-
-
-
-
-
-
-
-
- ..\..\sharpcompress\
- true
-
-
- true
- full
- false
- ..\bin\
- TRACE;DEBUG;DISABLE_TRACE;UNSIGNED
- prompt
- 4
- true
- true
- AllRules.ruleset
- 1591
-
-
-
-
- pdbonly
- true
- ..\bin\
- TRACE;UNSIGNED
- prompt
- 4
- true
- AllRules.ruleset
-
-
- 1591
- true
-
-
- false
-
-
- SharpCompress.pfx
-
-
-
-
- 3.5
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
- Code
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
- .NET Framework 3.5 SP1 Client Profile
- false
-
-
- False
- .NET Framework 3.5 SP1
- true
-
-
- False
- Windows Installer 3.1
- true
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpCompress/SharpCompress.WindowsStore.csproj b/SharpCompress/SharpCompress.WindowsStore.csproj
deleted file mode 100644
index 4d4865e6..00000000
--- a/SharpCompress/SharpCompress.WindowsStore.csproj
+++ /dev/null
@@ -1,340 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- 8.0.30703
- 2.0
- {1DF6D83C-31FF-47B6-82FE-C4603BE916B5}
- Library
- Properties
- SharpCompress
- SharpCompress
- en-US
- 512
- {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- obj\WindowsStore\
- 8.1
- 12
-
-
-
- true
- full
- false
- ..\bin\WindowsStore\
- DEBUG;TRACE;NETFX_CORE
- prompt
- 4
-
-
- pdbonly
- true
- ..\bin\WindowsStore\
- TRACE;NETFX_CORE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 12.0
-
-
-
-
-
- true
-
-
- SharpCompress.pfx
-
-
-
-
\ No newline at end of file
diff --git a/SharpCompress/SharpCompress.csproj b/SharpCompress/SharpCompress.csproj
deleted file mode 100644
index acbd0c10..00000000
--- a/SharpCompress/SharpCompress.csproj
+++ /dev/null
@@ -1,397 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {10A689CF-76A2-4A4F-96E4-553C33398438}
- Library
- Properties
- SharpCompress
- SharpCompress
- v4.0
- 512
-
-
-
-
- 3.5
-
- publish\
- true
- Disk
- false
- Foreground
- 7
- Days
- false
- false
- true
- 0
- 1.0.0.%2a
- false
- false
- true
- Client
- obj\Full\
-
-
-
-
-
-
-
-
- ..\..\sharpcompress\
- true
-
-
- true
- full
- false
- ..\bin\Full\
- TRACE;DEBUG;DISABLE_TRACE
- prompt
- 4
- true
- true
- AllRules.ruleset
- 1591
-
-
-
-
- pdbonly
- true
- ..\bin\Full\
- TRACE
- prompt
- 4
- true
- AllRules.ruleset
-
-
- 1591
- true
-
-
- true
-
-
- SharpCompress.pfx
-
-
-
-
- 3.5
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
- Code
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
- .NET Framework 3.5 SP1 Client Profile
- false
-
-
- False
- .NET Framework 3.5 SP1
- true
-
-
- False
- Windows Installer 3.1
- true
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpCompress/VersionInfo.cs b/SharpCompress/VersionInfo.cs
deleted file mode 100644
index f888f7e8..00000000
--- a/SharpCompress/VersionInfo.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System.Reflection;
-#if !PORTABLE
-using System.Runtime.InteropServices;
-
-[assembly: ComVisible(false)]
-#endif
-
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyCopyright("Copyright © Adam Hathcock")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("0.11.6.0")]
-[assembly: AssemblyFileVersion("0.11.6.0")]
\ No newline at end of file
diff --git a/SharpCompress/sharpcompress.DotSettings b/SharpCompress/sharpcompress.DotSettings
deleted file mode 100644
index cb391bb6..00000000
--- a/SharpCompress/sharpcompress.DotSettings
+++ /dev/null
@@ -1,134 +0,0 @@
-
- True
- True
- True
- True
- True
- True
- False
- True
- True
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- DoHide
- True
- ERROR
- ERROR
- ERROR
- ERROR
- ERROR
- DO_NOT_SHOW
- DO_NOT_SHOW
- DO_NOT_SHOW
- ERROR
- DO_NOT_SHOW
- <?xml version="1.0" encoding="utf-16"?><Profile name="Adam Clean"><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>ALWAYS_IMPLICIT</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSShortenReferences>True</CSShortenReferences><HtmlReformatCode>True</HtmlReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier></Profile>
- <?xml version="1.0" encoding="utf-16"?><Profile name="NaaS Clean"><CSReformatCode>True</CSReformatCode><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReorderTypeMembers>True</CSReorderTypeMembers><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty></Profile>
- NaaS Clean
- Default: Full Cleanup
- True
- NEXT_LINE
- NEXT_LINE
- SEPARATE
- True
- True
- True
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- True
- NEXT_LINE
- False
- False
- False
- False
- False
- False
- False
- True
- LINE_BREAK
- False
- False
- True
- WRAP_IF_LONG
- WRAP_IF_LONG
- WRAP_IF_LONG
- CHOP_ALWAYS
- CHOP_ALWAYS
- WRAP_IF_LONG
- True
- True
- True
- False
- True
- Automatic property
- True
- False
- False
- True
- False
- False
- True
- False
- False
- True
- False
- False
- EC
- IIS
- <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
- <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- $object$_On$event$
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" />
- <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
- True
- True
- True
- True
\ No newline at end of file
diff --git a/global.json b/global.json
new file mode 100644
index 00000000..d0f936b5
--- /dev/null
+++ b/global.json
@@ -0,0 +1,3 @@
+{
+ "projects": ["src","test"]
+}
diff --git a/SharpCompress/Archive/AbstractArchive.cs b/src/SharpCompress/Archive/AbstractArchive.cs
similarity index 97%
rename from SharpCompress/Archive/AbstractArchive.cs
rename to src/SharpCompress/Archive/AbstractArchive.cs
index 5e185484..4d1e9d30 100644
--- a/SharpCompress/Archive/AbstractArchive.cs
+++ b/src/SharpCompress/Archive/AbstractArchive.cs
@@ -1,212 +1,212 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Reader;
-
-namespace SharpCompress.Archive
-{
- public abstract class AbstractArchive : IArchive, IArchiveExtractionListener
- where TEntry : IArchiveEntry
- where TVolume : IVolume
- {
- private readonly LazyReadOnlyCollection lazyVolumes;
- private readonly LazyReadOnlyCollection lazyEntries;
-
- public event EventHandler> EntryExtractionBegin;
- public event EventHandler> EntryExtractionEnd;
-
- public event EventHandler CompressedBytesRead;
- public event EventHandler FilePartExtractionBegin;
-
- protected string Password { get; private set; }
-
-#if !PORTABLE && !NETFX_CORE
- internal AbstractArchive(ArchiveType type, FileInfo fileInfo, Options options, string password)
- {
- Type = type;
- Password = password;
- if (!fileInfo.Exists)
- {
- throw new ArgumentException("File does not exist: " + fileInfo.FullName);
- }
- options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
- lazyVolumes = new LazyReadOnlyCollection(LoadVolumes(fileInfo, options));
- lazyEntries = new LazyReadOnlyCollection(LoadEntries(Volumes));
- }
-
-
- protected abstract IEnumerable LoadVolumes(FileInfo file, Options options);
-#endif
-
- internal AbstractArchive(ArchiveType type, IEnumerable streams, Options options, string password)
- {
- Type = type;
- Password = password;
- lazyVolumes = new LazyReadOnlyCollection(LoadVolumes(streams.Select(CheckStreams), options));
- lazyEntries = new LazyReadOnlyCollection(LoadEntries(Volumes));
- }
-
- internal AbstractArchive(ArchiveType type)
- {
- Type = type;
- lazyVolumes = new LazyReadOnlyCollection(Enumerable.Empty());
- lazyEntries = new LazyReadOnlyCollection(Enumerable.Empty());
- }
- public ArchiveType Type { get; private set; }
-
- void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry)
- {
- if (EntryExtractionBegin != null)
- {
- EntryExtractionBegin(this, new ArchiveExtractionEventArgs(entry));
- }
- }
-
- void IArchiveExtractionListener.FireEntryExtractionEnd(IArchiveEntry entry)
- {
- if (EntryExtractionEnd != null)
- {
- EntryExtractionEnd(this, new ArchiveExtractionEventArgs(entry));
- }
- }
-
- private static Stream CheckStreams(Stream stream)
- {
- if (!stream.CanSeek || !stream.CanRead)
- {
- throw new ArgumentException("Archive streams must be Readable and Seekable");
- }
- return stream;
- }
-
- ///
- /// Returns an ReadOnlyCollection of all the RarArchiveEntries across the one or many parts of the RarArchive.
- ///
- public virtual ICollection Entries
- {
- get { return lazyEntries; }
- }
-
- ///
- /// Returns an ReadOnlyCollection of all the RarArchiveVolumes across the one or many parts of the RarArchive.
- ///
- public ICollection Volumes
- {
- get { return lazyVolumes; }
- }
-
- ///
- /// The total size of the files compressed in the archive.
- ///
- public virtual long TotalSize
- {
- get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); }
- }
-
- ///
- /// The total size of the files as uncompressed in the archive.
- ///
- public virtual long TotalUncompressSize
- {
- get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); }
- }
-
- protected abstract IEnumerable LoadVolumes(IEnumerable streams, Options options);
- protected abstract IEnumerable LoadEntries(IEnumerable volumes);
-
- IEnumerable IArchive.Entries
- {
- get { return Entries.Cast(); }
- }
-
- IEnumerable IArchive.Volumes
- {
- get { return lazyVolumes.Cast(); }
- }
-
- private bool disposed;
-
- public virtual void Dispose()
- {
- if (!disposed)
- {
- lazyVolumes.ForEach(v => v.Dispose());
- lazyEntries.GetLoaded().Cast().ForEach(x => x.Close());
- disposed = true;
- }
- }
-
- void IArchiveExtractionListener.EnsureEntriesLoaded()
- {
- lazyEntries.EnsureFullyLoaded();
- lazyVolumes.EnsureFullyLoaded();
- }
-
- void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes)
- {
- if (CompressedBytesRead != null)
- {
- CompressedBytesRead(this, new CompressedBytesReadEventArgs()
- {
- CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
- CompressedBytesRead = compressedReadBytes
- });
- }
- }
-
- void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize)
- {
- if (FilePartExtractionBegin != null)
- {
- FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs()
- {
- CompressedSize = compressedSize,
- Size = size,
- Name = name,
- });
- }
- }
-
- ///
- /// Use this method to extract all entries in an archive in order.
- /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
- /// extracted sequentially for the best performance.
- ///
- /// This method will load all entry information from the archive.
- ///
- /// WARNING: this will reuse the underlying stream for the archive. Errors may
- /// occur if this is used at the same time as other extraction methods on this instance.
- ///
- ///
- public IReader ExtractAllEntries()
- {
- ((IArchiveExtractionListener)this).EnsureEntriesLoaded();
- return CreateReaderForSolidExtraction();
- }
-
- protected abstract IReader CreateReaderForSolidExtraction();
-
- ///
- /// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
- ///
- public virtual bool IsSolid
- {
- get { return false; }
- }
-
-
- ///
- /// The archive can find all the parts of the archive needed to fully extract the archive. This forces the parsing of the entire archive.
- ///
- public bool IsComplete
- {
- get
- {
- ((IArchiveExtractionListener)this).EnsureEntriesLoaded();
- return Entries.All(x => x.IsComplete);
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Reader;
+
+namespace SharpCompress.Archive
+{
+ public abstract class AbstractArchive : IArchive, IArchiveExtractionListener
+ where TEntry : IArchiveEntry
+ where TVolume : IVolume
+ {
+ private readonly LazyReadOnlyCollection lazyVolumes;
+ private readonly LazyReadOnlyCollection lazyEntries;
+
+ public event EventHandler> EntryExtractionBegin;
+ public event EventHandler> EntryExtractionEnd;
+
+ public event EventHandler CompressedBytesRead;
+ public event EventHandler FilePartExtractionBegin;
+
+ protected string Password { get; private set; }
+
+#if !NO_FILE
+ internal AbstractArchive(ArchiveType type, FileInfo fileInfo, Options options, string password)
+ {
+ Type = type;
+ Password = password;
+ if (!fileInfo.Exists)
+ {
+ throw new ArgumentException("File does not exist: " + fileInfo.FullName);
+ }
+ options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
+ lazyVolumes = new LazyReadOnlyCollection(LoadVolumes(fileInfo, options));
+ lazyEntries = new LazyReadOnlyCollection(LoadEntries(Volumes));
+ }
+
+
+ protected abstract IEnumerable LoadVolumes(FileInfo file, Options options);
+#endif
+
+ internal AbstractArchive(ArchiveType type, IEnumerable streams, Options options, string password)
+ {
+ Type = type;
+ Password = password;
+ lazyVolumes = new LazyReadOnlyCollection(LoadVolumes(streams.Select(CheckStreams), options));
+ lazyEntries = new LazyReadOnlyCollection(LoadEntries(Volumes));
+ }
+
+ internal AbstractArchive(ArchiveType type)
+ {
+ Type = type;
+ lazyVolumes = new LazyReadOnlyCollection(Enumerable.Empty());
+ lazyEntries = new LazyReadOnlyCollection(Enumerable.Empty());
+ }
+ public ArchiveType Type { get; private set; }
+
+ void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry)
+ {
+ if (EntryExtractionBegin != null)
+ {
+ EntryExtractionBegin(this, new ArchiveExtractionEventArgs(entry));
+ }
+ }
+
+ void IArchiveExtractionListener.FireEntryExtractionEnd(IArchiveEntry entry)
+ {
+ if (EntryExtractionEnd != null)
+ {
+ EntryExtractionEnd(this, new ArchiveExtractionEventArgs(entry));
+ }
+ }
+
+ private static Stream CheckStreams(Stream stream)
+ {
+ if (!stream.CanSeek || !stream.CanRead)
+ {
+ throw new ArgumentException("Archive streams must be Readable and Seekable");
+ }
+ return stream;
+ }
+
+ ///
+ /// Returns an ReadOnlyCollection of all the RarArchiveEntries across the one or many parts of the RarArchive.
+ ///
+ public virtual ICollection Entries
+ {
+ get { return lazyEntries; }
+ }
+
+ ///
+ /// Returns an ReadOnlyCollection of all the RarArchiveVolumes across the one or many parts of the RarArchive.
+ ///
+ public ICollection Volumes
+ {
+ get { return lazyVolumes; }
+ }
+
+ ///
+ /// The total size of the files compressed in the archive.
+ ///
+ public virtual long TotalSize
+ {
+ get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); }
+ }
+
+ ///
+ /// The total size of the files as uncompressed in the archive.
+ ///
+ public virtual long TotalUncompressSize
+ {
+ get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); }
+ }
+
+ protected abstract IEnumerable LoadVolumes(IEnumerable streams, Options options);
+ protected abstract IEnumerable LoadEntries(IEnumerable volumes);
+
+ IEnumerable IArchive.Entries
+ {
+ get { return Entries.Cast(); }
+ }
+
+ IEnumerable IArchive.Volumes
+ {
+ get { return lazyVolumes.Cast(); }
+ }
+
+ private bool disposed;
+
+ public virtual void Dispose()
+ {
+ if (!disposed)
+ {
+ lazyVolumes.ForEach(v => v.Dispose());
+ lazyEntries.GetLoaded().Cast().ForEach(x => x.Close());
+ disposed = true;
+ }
+ }
+
+ void IArchiveExtractionListener.EnsureEntriesLoaded()
+ {
+ lazyEntries.EnsureFullyLoaded();
+ lazyVolumes.EnsureFullyLoaded();
+ }
+
+ void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes)
+ {
+ if (CompressedBytesRead != null)
+ {
+ CompressedBytesRead(this, new CompressedBytesReadEventArgs()
+ {
+ CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
+ CompressedBytesRead = compressedReadBytes
+ });
+ }
+ }
+
+ void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize)
+ {
+ if (FilePartExtractionBegin != null)
+ {
+ FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs()
+ {
+ CompressedSize = compressedSize,
+ Size = size,
+ Name = name,
+ });
+ }
+ }
+
+ ///
+ /// Use this method to extract all entries in an archive in order.
+ /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
+ /// extracted sequentially for the best performance.
+ ///
+ /// This method will load all entry information from the archive.
+ ///
+ /// WARNING: this will reuse the underlying stream for the archive. Errors may
+ /// occur if this is used at the same time as other extraction methods on this instance.
+ ///
+ ///
+ public IReader ExtractAllEntries()
+ {
+ ((IArchiveExtractionListener)this).EnsureEntriesLoaded();
+ return CreateReaderForSolidExtraction();
+ }
+
+ protected abstract IReader CreateReaderForSolidExtraction();
+
+ ///
+ /// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
+ ///
+ public virtual bool IsSolid
+ {
+ get { return false; }
+ }
+
+
+ ///
+ /// The archive can find all the parts of the archive needed to fully extract the archive. This forces the parsing of the entire archive.
+ ///
+ public bool IsComplete
+ {
+ get
+ {
+ ((IArchiveExtractionListener)this).EnsureEntriesLoaded();
+ return Entries.All(x => x.IsComplete);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/AbstractWritableArchive.cs b/src/SharpCompress/Archive/AbstractWritableArchive.cs
similarity index 96%
rename from SharpCompress/Archive/AbstractWritableArchive.cs
rename to src/SharpCompress/Archive/AbstractWritableArchive.cs
index beccb4f8..8b0410aa 100644
--- a/SharpCompress/Archive/AbstractWritableArchive.cs
+++ b/src/SharpCompress/Archive/AbstractWritableArchive.cs
@@ -1,149 +1,149 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-
-namespace SharpCompress.Archive
-{
- public abstract class AbstractWritableArchive : AbstractArchive, IWritableArchive
- where TEntry : IArchiveEntry
- where TVolume : IVolume
- {
- private readonly List newEntries = new List();
- private readonly List removedEntries = new List();
-
- private readonly List modifiedEntries = new List();
- private bool hasModifications;
-
- internal AbstractWritableArchive(ArchiveType type)
- : base(type)
- {
- }
-
- internal AbstractWritableArchive(ArchiveType type, Stream stream, Options options)
- : base(type, stream.AsEnumerable(), options, null)
- {
- }
-
-#if !PORTABLE && !NETFX_CORE
- internal AbstractWritableArchive(ArchiveType type, FileInfo fileInfo, Options options)
- : base(type, fileInfo, options, null)
- {
- }
-#endif
-
- public override ICollection Entries
- {
- get
- {
- if (hasModifications)
- {
- return modifiedEntries;
- }
- return base.Entries;
- }
- }
-
- private void RebuildModifiedCollection()
- {
- hasModifications = true;
- newEntries.RemoveAll(v => removedEntries.Contains(v));
- modifiedEntries.Clear();
- modifiedEntries.AddRange(OldEntries.Concat(newEntries));
- }
-
- private IEnumerable OldEntries
- {
- get { return base.Entries.Where(x => !removedEntries.Contains(x)); }
- }
-
- public void RemoveEntry(TEntry entry)
- {
- if (!removedEntries.Contains(entry))
- {
- removedEntries.Add(entry);
- RebuildModifiedCollection();
- }
- }
- void IWritableArchive.RemoveEntry(IArchiveEntry entry)
- {
- RemoveEntry((TEntry)entry);
- }
-
- public TEntry AddEntry(string key, Stream source,
- long size = 0, DateTime? modified = null)
- {
- return AddEntry(key, source, false, size, modified);
- }
-
-
- IArchiveEntry IWritableArchive.AddEntry(string key, Stream source, bool closeStream, long size, DateTime? modified)
- {
- return AddEntry(key, source, closeStream, size, modified);
- }
-
- public TEntry AddEntry(string key, Stream source, bool closeStream,
- long size = 0, DateTime? modified = null)
- {
- if (key.StartsWith("/")
- || key.StartsWith("\\"))
- {
- key = key.Substring(1);
- }
- if (DoesKeyMatchExisting(key))
- {
- throw new ArchiveException("Cannot add entry with duplicate key: " + key);
- }
- var entry = CreateEntry(key, source, size, modified, closeStream);
- newEntries.Add(entry);
- RebuildModifiedCollection();
- return entry;
- }
-
- private bool DoesKeyMatchExisting(string key)
- {
- foreach (var path in Entries.Select(x => x.Key))
- {
- var p = path.Replace('/','\\');
- if (p.StartsWith("\\"))
- {
- p = p.Substring(1);
- }
- return string.Equals(p, key, StringComparison.OrdinalIgnoreCase);
- }
- return false;
- }
-
- public void SaveTo(Stream stream, CompressionInfo compressionType)
- {
- //reset streams of new entries
- newEntries.Cast().ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin));
- SaveTo(stream, compressionType, OldEntries, newEntries);
- }
-
- protected TEntry CreateEntry(string key, Stream source, long size, DateTime? modified,
- bool closeStream)
- {
- if (!source.CanRead || !source.CanSeek)
- {
- throw new ArgumentException("Streams must be readable and seekable to use the Writing Archive API");
- }
- return CreateEntryInternal(key, source, size, modified, closeStream);
- }
-
- protected abstract TEntry CreateEntryInternal(string key, Stream source, long size, DateTime? modified,
- bool closeStream);
-
- protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
- IEnumerable oldEntries, IEnumerable newEntries);
-
- public override void Dispose()
- {
- base.Dispose();
- newEntries.Cast().ForEach(x => x.Close());
- removedEntries.Cast().ForEach(x => x.Close());
- modifiedEntries.Cast().ForEach(x => x.Close());
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+
+namespace SharpCompress.Archive
+{
+ public abstract class AbstractWritableArchive : AbstractArchive, IWritableArchive
+ where TEntry : IArchiveEntry
+ where TVolume : IVolume
+ {
+ private readonly List newEntries = new List();
+ private readonly List removedEntries = new List();
+
+ private readonly List modifiedEntries = new List();
+ private bool hasModifications;
+
+ internal AbstractWritableArchive(ArchiveType type)
+ : base(type)
+ {
+ }
+
+ internal AbstractWritableArchive(ArchiveType type, Stream stream, Options options)
+ : base(type, stream.AsEnumerable(), options, null)
+ {
+ }
+
+#if !NO_FILE
+ internal AbstractWritableArchive(ArchiveType type, FileInfo fileInfo, Options options)
+ : base(type, fileInfo, options, null)
+ {
+ }
+#endif
+
+ public override ICollection Entries
+ {
+ get
+ {
+ if (hasModifications)
+ {
+ return modifiedEntries;
+ }
+ return base.Entries;
+ }
+ }
+
+ private void RebuildModifiedCollection()
+ {
+ hasModifications = true;
+ newEntries.RemoveAll(v => removedEntries.Contains(v));
+ modifiedEntries.Clear();
+ modifiedEntries.AddRange(OldEntries.Concat(newEntries));
+ }
+
+ private IEnumerable OldEntries
+ {
+ get { return base.Entries.Where(x => !removedEntries.Contains(x)); }
+ }
+
+ public void RemoveEntry(TEntry entry)
+ {
+ if (!removedEntries.Contains(entry))
+ {
+ removedEntries.Add(entry);
+ RebuildModifiedCollection();
+ }
+ }
+ void IWritableArchive.RemoveEntry(IArchiveEntry entry)
+ {
+ RemoveEntry((TEntry)entry);
+ }
+
+ public TEntry AddEntry(string key, Stream source,
+ long size = 0, DateTime? modified = null)
+ {
+ return AddEntry(key, source, false, size, modified);
+ }
+
+
+ IArchiveEntry IWritableArchive.AddEntry(string key, Stream source, bool closeStream, long size, DateTime? modified)
+ {
+ return AddEntry(key, source, closeStream, size, modified);
+ }
+
+ public TEntry AddEntry(string key, Stream source, bool closeStream,
+ long size = 0, DateTime? modified = null)
+ {
+ if (key.StartsWith("/")
+ || key.StartsWith("\\"))
+ {
+ key = key.Substring(1);
+ }
+ if (DoesKeyMatchExisting(key))
+ {
+ throw new ArchiveException("Cannot add entry with duplicate key: " + key);
+ }
+ var entry = CreateEntry(key, source, size, modified, closeStream);
+ newEntries.Add(entry);
+ RebuildModifiedCollection();
+ return entry;
+ }
+
+ private bool DoesKeyMatchExisting(string key)
+ {
+ foreach (var path in Entries.Select(x => x.Key))
+ {
+ var p = path.Replace('/','\\');
+ if (p.StartsWith("\\"))
+ {
+ p = p.Substring(1);
+ }
+ return string.Equals(p, key, StringComparison.OrdinalIgnoreCase);
+ }
+ return false;
+ }
+
+ public void SaveTo(Stream stream, CompressionInfo compressionType)
+ {
+ //reset streams of new entries
+ newEntries.Cast().ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin));
+ SaveTo(stream, compressionType, OldEntries, newEntries);
+ }
+
+ protected TEntry CreateEntry(string key, Stream source, long size, DateTime? modified,
+ bool closeStream)
+ {
+ if (!source.CanRead || !source.CanSeek)
+ {
+ throw new ArgumentException("Streams must be readable and seekable to use the Writing Archive API");
+ }
+ return CreateEntryInternal(key, source, size, modified, closeStream);
+ }
+
+ protected abstract TEntry CreateEntryInternal(string key, Stream source, long size, DateTime? modified,
+ bool closeStream);
+
+ protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
+ IEnumerable oldEntries, IEnumerable newEntries);
+
+ public override void Dispose()
+ {
+ base.Dispose();
+ newEntries.Cast().ForEach(x => x.Close());
+ removedEntries.Cast().ForEach(x => x.Close());
+ modifiedEntries.Cast().ForEach(x => x.Close());
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/ArchiveFactory.cs b/src/SharpCompress/Archive/ArchiveFactory.cs
similarity index 96%
rename from SharpCompress/Archive/ArchiveFactory.cs
rename to src/SharpCompress/Archive/ArchiveFactory.cs
index 8dddbe82..60b42fcb 100644
--- a/SharpCompress/Archive/ArchiveFactory.cs
+++ b/src/SharpCompress/Archive/ArchiveFactory.cs
@@ -1,172 +1,172 @@
-using System;
-using System.IO;
-using SharpCompress.Archive.GZip;
-using SharpCompress.Archive.Rar;
-using SharpCompress.Archive.SevenZip;
-using SharpCompress.Archive.Tar;
-using SharpCompress.Archive.Zip;
-using SharpCompress.Common;
-
-namespace SharpCompress.Archive
-{
- public class ArchiveFactory
- {
- ///
- /// Opens an Archive for random access
- ///
- ///
- ///
- ///
- public static IArchive Open(Stream stream, Options options = Options.KeepStreamsOpen)
- {
- stream.CheckNotNull("stream");
- if (!stream.CanRead || !stream.CanSeek)
- {
- throw new ArgumentException("Stream should be readable and seekable");
- }
-
- if (ZipArchive.IsZipFile(stream, null))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return ZipArchive.Open(stream, options, null);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (SevenZipArchive.IsSevenZipFile(stream))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return SevenZipArchive.Open(stream, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (GZipArchive.IsGZipFile(stream))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return GZipArchive.Open(stream, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (RarArchive.IsRarFile(stream, options))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return RarArchive.Open(stream, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (TarArchive.IsTarFile(stream))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return TarArchive.Open(stream, options);
- }
- throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
- }
-
- public static IWritableArchive Create(ArchiveType type)
- {
- switch (type)
- {
- case ArchiveType.Zip:
- {
- return ZipArchive.Create();
- }
- case ArchiveType.Tar:
- {
- return TarArchive.Create();
- }
- case ArchiveType.GZip:
- {
- return GZipArchive.Create();
- }
- default:
- {
- throw new NotSupportedException("Cannot create Archives of type: " + type);
- }
- }
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- public static IArchive Open(string filePath)
- {
- return Open(filePath, Options.None);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- public static IArchive Open(FileInfo fileInfo)
- {
- return Open(fileInfo, Options.None);
- }
-
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- public static IArchive Open(string filePath, Options options)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- public static IArchive Open(FileInfo fileInfo, Options options)
- {
- fileInfo.CheckNotNull("fileInfo");
- using (var stream = fileInfo.OpenRead())
- {
- if (ZipArchive.IsZipFile(stream, null))
- {
- stream.Dispose();
- return ZipArchive.Open(fileInfo, options, null);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (SevenZipArchive.IsSevenZipFile(stream))
- {
- stream.Dispose();
- return SevenZipArchive.Open(fileInfo, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (GZipArchive.IsGZipFile(stream))
- {
- stream.Dispose();
- return GZipArchive.Open(fileInfo, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (RarArchive.IsRarFile(stream, options))
- {
- stream.Dispose();
- return RarArchive.Open(fileInfo, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
- if (TarArchive.IsTarFile(stream))
- {
- stream.Dispose();
- return TarArchive.Open(fileInfo, options);
- }
- throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
- }
- }
-
- ///
- /// Extract to specific directory, retaining filename
- ///
- public static void WriteToDirectory(string sourceArchive, string destinationDirectory,
- ExtractOptions options = ExtractOptions.Overwrite)
- {
- using (IArchive archive = Open(sourceArchive))
- {
- foreach (IArchiveEntry entry in archive.Entries)
- {
- entry.WriteToDirectory(destinationDirectory, options);
- }
- }
- }
-#endif
- }
+using System;
+using System.IO;
+using SharpCompress.Archive.GZip;
+using SharpCompress.Archive.Rar;
+using SharpCompress.Archive.SevenZip;
+using SharpCompress.Archive.Tar;
+using SharpCompress.Archive.Zip;
+using SharpCompress.Common;
+
+namespace SharpCompress.Archive
+{
+ public class ArchiveFactory
+ {
+ ///
+ /// Opens an Archive for random access
+ ///
+ ///
+ ///
+ ///
+ public static IArchive Open(Stream stream, Options options = Options.KeepStreamsOpen)
+ {
+ stream.CheckNotNull("stream");
+ if (!stream.CanRead || !stream.CanSeek)
+ {
+ throw new ArgumentException("Stream should be readable and seekable");
+ }
+
+ if (ZipArchive.IsZipFile(stream, null))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return ZipArchive.Open(stream, options, null);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (SevenZipArchive.IsSevenZipFile(stream))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return SevenZipArchive.Open(stream, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (GZipArchive.IsGZipFile(stream))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return GZipArchive.Open(stream, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (RarArchive.IsRarFile(stream, options))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return RarArchive.Open(stream, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (TarArchive.IsTarFile(stream))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return TarArchive.Open(stream, options);
+ }
+ throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
+ }
+
+ public static IWritableArchive Create(ArchiveType type)
+ {
+ switch (type)
+ {
+ case ArchiveType.Zip:
+ {
+ return ZipArchive.Create();
+ }
+ case ArchiveType.Tar:
+ {
+ return TarArchive.Create();
+ }
+ case ArchiveType.GZip:
+ {
+ return GZipArchive.Create();
+ }
+ default:
+ {
+ throw new NotSupportedException("Cannot create Archives of type: " + type);
+ }
+ }
+ }
+
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ public static IArchive Open(string filePath)
+ {
+ return Open(filePath, Options.None);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ public static IArchive Open(FileInfo fileInfo)
+ {
+ return Open(fileInfo, Options.None);
+ }
+
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ public static IArchive Open(string filePath, Options options)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ public static IArchive Open(FileInfo fileInfo, Options options)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ using (var stream = fileInfo.OpenRead())
+ {
+ if (ZipArchive.IsZipFile(stream, null))
+ {
+ stream.Dispose();
+ return ZipArchive.Open(fileInfo, options, null);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (SevenZipArchive.IsSevenZipFile(stream))
+ {
+ stream.Dispose();
+ return SevenZipArchive.Open(fileInfo, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (GZipArchive.IsGZipFile(stream))
+ {
+ stream.Dispose();
+ return GZipArchive.Open(fileInfo, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (RarArchive.IsRarFile(stream, options))
+ {
+ stream.Dispose();
+ return RarArchive.Open(fileInfo, options);
+ }
+ stream.Seek(0, SeekOrigin.Begin);
+ if (TarArchive.IsTarFile(stream))
+ {
+ stream.Dispose();
+ return TarArchive.Open(fileInfo, options);
+ }
+ throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
+ }
+ }
+
+ ///
+ /// Extract to specific directory, retaining filename
+ ///
+ public static void WriteToDirectory(string sourceArchive, string destinationDirectory,
+ ExtractOptions options = ExtractOptions.Overwrite)
+ {
+ using (IArchive archive = Open(sourceArchive))
+ {
+ foreach (IArchiveEntry entry in archive.Entries)
+ {
+ entry.WriteToDirectory(destinationDirectory, options);
+ }
+ }
+ }
+#endif
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/GZip/GZipArchive.cs b/src/SharpCompress/Archive/GZip/GZipArchive.cs
similarity index 96%
rename from SharpCompress/Archive/GZip/GZipArchive.cs
rename to src/SharpCompress/Archive/GZip/GZipArchive.cs
index c1714cb5..2de0a2bd 100644
--- a/SharpCompress/Archive/GZip/GZipArchive.cs
+++ b/src/SharpCompress/Archive/GZip/GZipArchive.cs
@@ -1,218 +1,218 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.GZip;
-using SharpCompress.Reader;
-using SharpCompress.Reader.GZip;
-using SharpCompress.Writer.GZip;
-
-namespace SharpCompress.Archive.GZip
-{
- public class GZipArchive : AbstractWritableArchive
- {
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- public static GZipArchive Open(string filePath)
- {
- return Open(filePath, Options.None);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- public static GZipArchive Open(FileInfo fileInfo)
- {
- return Open(fileInfo, Options.None);
- }
-
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- public static GZipArchive Open(string filePath, Options options)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- public static GZipArchive Open(FileInfo fileInfo, Options options)
- {
- fileInfo.CheckNotNull("fileInfo");
- return new GZipArchive(fileInfo, options);
- }
-#endif
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- public static GZipArchive Open(Stream stream)
- {
- stream.CheckNotNull("stream");
- return Open(stream, Options.None);
- }
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- public static GZipArchive Open(Stream stream, Options options)
- {
- stream.CheckNotNull("stream");
- return new GZipArchive(stream, options);
- }
-
- public static GZipArchive Create()
- {
- return new GZipArchive();
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- internal GZipArchive(FileInfo fileInfo, Options options)
- : base(ArchiveType.GZip, fileInfo, options)
- {
- }
-
- protected override IEnumerable LoadVolumes(FileInfo file, Options options)
- {
- return new GZipVolume(file, options).AsEnumerable();
- }
-
- public static bool IsGZipFile(string filePath)
- {
- return IsGZipFile(new FileInfo(filePath));
- }
-
- public static bool IsGZipFile(FileInfo fileInfo)
- {
- if (!fileInfo.Exists)
- {
- return false;
- }
- using (Stream stream = fileInfo.OpenRead())
- {
- return IsGZipFile(stream);
- }
- }
-
- public void SaveTo(string filePath)
- {
- SaveTo(new FileInfo(filePath));
- }
-
- public void SaveTo(FileInfo fileInfo)
- {
- using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
- {
- SaveTo(stream);
- }
- }
-#endif
-
- public static bool IsGZipFile(Stream stream)
- {
- // read the header on the first read
- byte[] header = new byte[10];
- int n = stream.Read(header, 0, header.Length);
-
- // workitem 8501: handle edge case (decompress empty stream)
- if (n == 0)
- return false;
-
- if (n != 10)
- return false;
-
- if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
- return false;
-
- return true;
- }
-
- ///
- /// Takes multiple seekable Streams for a multi-part archive
- ///
- ///
- ///
- internal GZipArchive(Stream stream, Options options)
- : base(ArchiveType.GZip, stream, options)
- {
- }
-
- internal GZipArchive()
- : base(ArchiveType.GZip)
- {
- }
-
- public void SaveTo(Stream stream)
- {
- SaveTo(stream, CompressionType.GZip);
- }
-
- protected override GZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
- bool closeStream)
- {
- if (Entries.Any())
- {
- throw new InvalidOperationException("Only one entry is allowed in a GZip Archive");
- }
- return new GZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
- }
-
- protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
- IEnumerable oldEntries,
- IEnumerable newEntries)
- {
- if (Entries.Count > 1)
- {
- throw new InvalidOperationException("Only one entry is allowed in a GZip Archive");
- }
- using (var writer = new GZipWriter(stream))
- {
- foreach (var entry in oldEntries.Concat(newEntries)
- .Where(x => !x.IsDirectory))
- {
- using (var entryStream = entry.OpenEntryStream())
- {
- writer.Write(entry.Key, entryStream, entry.LastModifiedTime);
- }
- }
- }
- }
-
- protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
- {
- return new GZipVolume(streams.First(), options).AsEnumerable();
- }
-
- protected override IEnumerable LoadEntries(IEnumerable volumes)
- {
- Stream stream = volumes.Single().Stream;
- yield return new GZipArchiveEntry(this, new GZipFilePart(stream));
- }
-
- protected override IReader CreateReaderForSolidExtraction()
- {
- var stream = Volumes.Single().Stream;
- stream.Position = 0;
- return GZipReader.Open(stream);
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.GZip;
+using SharpCompress.Reader;
+using SharpCompress.Reader.GZip;
+using SharpCompress.Writer.GZip;
+
+namespace SharpCompress.Archive.GZip
+{
+ public class GZipArchive : AbstractWritableArchive
+ {
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ public static GZipArchive Open(string filePath)
+ {
+ return Open(filePath, Options.None);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ public static GZipArchive Open(FileInfo fileInfo)
+ {
+ return Open(fileInfo, Options.None);
+ }
+
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ public static GZipArchive Open(string filePath, Options options)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ public static GZipArchive Open(FileInfo fileInfo, Options options)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ return new GZipArchive(fileInfo, options);
+ }
+#endif
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ public static GZipArchive Open(Stream stream)
+ {
+ stream.CheckNotNull("stream");
+ return Open(stream, Options.None);
+ }
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ public static GZipArchive Open(Stream stream, Options options)
+ {
+ stream.CheckNotNull("stream");
+ return new GZipArchive(stream, options);
+ }
+
+ public static GZipArchive Create()
+ {
+ return new GZipArchive();
+ }
+
+#if !NO_FILE
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ internal GZipArchive(FileInfo fileInfo, Options options)
+ : base(ArchiveType.GZip, fileInfo, options)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(FileInfo file, Options options)
+ {
+ return new GZipVolume(file, options).AsEnumerable();
+ }
+
+ public static bool IsGZipFile(string filePath)
+ {
+ return IsGZipFile(new FileInfo(filePath));
+ }
+
+ public static bool IsGZipFile(FileInfo fileInfo)
+ {
+ if (!fileInfo.Exists)
+ {
+ return false;
+ }
+ using (Stream stream = fileInfo.OpenRead())
+ {
+ return IsGZipFile(stream);
+ }
+ }
+
+ public void SaveTo(string filePath)
+ {
+ SaveTo(new FileInfo(filePath));
+ }
+
+ public void SaveTo(FileInfo fileInfo)
+ {
+ using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
+ {
+ SaveTo(stream);
+ }
+ }
+#endif
+
+ public static bool IsGZipFile(Stream stream)
+ {
+ // read the header on the first read
+ byte[] header = new byte[10];
+ int n = stream.Read(header, 0, header.Length);
+
+ // workitem 8501: handle edge case (decompress empty stream)
+ if (n == 0)
+ return false;
+
+ if (n != 10)
+ return false;
+
+ if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
+ return false;
+
+ return true;
+ }
+
+ ///
+ /// Takes multiple seekable Streams for a multi-part archive
+ ///
+ ///
+ ///
+ internal GZipArchive(Stream stream, Options options)
+ : base(ArchiveType.GZip, stream, options)
+ {
+ }
+
+ internal GZipArchive()
+ : base(ArchiveType.GZip)
+ {
+ }
+
+ public void SaveTo(Stream stream)
+ {
+ SaveTo(stream, CompressionType.GZip);
+ }
+
+ protected override GZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
+ bool closeStream)
+ {
+ if (Entries.Any())
+ {
+ throw new InvalidOperationException("Only one entry is allowed in a GZip Archive");
+ }
+ return new GZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
+ }
+
+ protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
+ IEnumerable oldEntries,
+ IEnumerable newEntries)
+ {
+ if (Entries.Count > 1)
+ {
+ throw new InvalidOperationException("Only one entry is allowed in a GZip Archive");
+ }
+ using (var writer = new GZipWriter(stream))
+ {
+ foreach (var entry in oldEntries.Concat(newEntries)
+ .Where(x => !x.IsDirectory))
+ {
+ using (var entryStream = entry.OpenEntryStream())
+ {
+ writer.Write(entry.Key, entryStream, entry.LastModifiedTime);
+ }
+ }
+ }
+ }
+
+ protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
+ {
+ return new GZipVolume(streams.First(), options).AsEnumerable();
+ }
+
+ protected override IEnumerable LoadEntries(IEnumerable volumes)
+ {
+ Stream stream = volumes.Single().Stream;
+ yield return new GZipArchiveEntry(this, new GZipFilePart(stream));
+ }
+
+ protected override IReader CreateReaderForSolidExtraction()
+ {
+ var stream = Volumes.Single().Stream;
+ stream.Position = 0;
+ return GZipReader.Open(stream);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/GZip/GZipArchiveEntry.cs b/src/SharpCompress/Archive/GZip/GZipArchiveEntry.cs
similarity index 95%
rename from SharpCompress/Archive/GZip/GZipArchiveEntry.cs
rename to src/SharpCompress/Archive/GZip/GZipArchiveEntry.cs
index 4526956d..6c46f7a1 100644
--- a/SharpCompress/Archive/GZip/GZipArchiveEntry.cs
+++ b/src/SharpCompress/Archive/GZip/GZipArchiveEntry.cs
@@ -1,31 +1,31 @@
-using System.IO;
-using System.Linq;
-using SharpCompress.Common.GZip;
-
-namespace SharpCompress.Archive.GZip
-{
- public class GZipArchiveEntry : GZipEntry, IArchiveEntry
- {
-
- internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part)
- : base(part)
- {
- Archive = archive;
- }
-
- public virtual Stream OpenEntryStream()
- {
- return Parts.Single().GetCompressedStream();
- }
-
- #region IArchiveEntry Members
- public IArchive Archive { get; private set; }
-
- public bool IsComplete
- {
- get { return true; }
- }
-
- #endregion
- }
+using System.IO;
+using System.Linq;
+using SharpCompress.Common.GZip;
+
+namespace SharpCompress.Archive.GZip
+{
+ public class GZipArchiveEntry : GZipEntry, IArchiveEntry
+ {
+
+ internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part)
+ : base(part)
+ {
+ Archive = archive;
+ }
+
+ public virtual Stream OpenEntryStream()
+ {
+ return Parts.Single().GetCompressedStream();
+ }
+
+ #region IArchiveEntry Members
+ public IArchive Archive { get; private set; }
+
+ public bool IsComplete
+ {
+ get { return true; }
+ }
+
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs b/src/SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs
similarity index 95%
rename from SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs
rename to src/SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs
index 8ef98379..0c5067b5 100644
--- a/SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archive/GZip/GZipWritableArchiveEntry.cs
@@ -1,111 +1,111 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive.GZip
-{
- internal class GZipWritableArchiveEntry : GZipArchiveEntry, IWritableArchiveEntry
- {
- private readonly string path;
- private readonly long size;
- private readonly DateTime? lastModified;
- private readonly bool closeStream;
- private readonly Stream stream;
-
- internal GZipWritableArchiveEntry(GZipArchive archive, Stream stream,
- string path, long size, DateTime? lastModified, bool closeStream)
- : base(archive, null)
- {
- this.stream = stream;
- this.path = path;
- this.size = size;
- this.lastModified = lastModified;
- this.closeStream = closeStream;
- }
-
- public override long Crc
- {
- get { return 0; }
- }
-
- public override string Key
- {
- get { return path; }
- }
-
- public override long CompressedSize
- {
- get { return 0; }
- }
-
- public override long Size
- {
- get { return size; }
- }
-
- public override DateTime? LastModifiedTime
- {
- get { return lastModified; }
- }
-
- public override DateTime? CreatedTime
- {
- get { return null; }
- }
-
- public override DateTime? LastAccessedTime
- {
- get { return null; }
- }
-
- public override DateTime? ArchivedTime
- {
- get { return null; }
- }
-
- public override bool IsEncrypted
- {
- get { return false; }
- }
-
- public override bool IsDirectory
- {
- get { return false; }
- }
-
- public override bool IsSplit
- {
- get { return false; }
- }
-
- internal override IEnumerable Parts
- {
- get { throw new NotImplementedException(); }
- }
-
- Stream IWritableArchiveEntry.Stream
- {
- get
- {
- return stream;
- }
- }
-
- public override Stream OpenEntryStream()
- {
- //ensure new stream is at the start, this could be reset
- stream.Seek(0, SeekOrigin.Begin);
- return new NonDisposingStream(stream);
- }
-
- internal override void Close()
- {
- if (closeStream)
- {
- stream.Dispose();
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive.GZip
+{
+ internal class GZipWritableArchiveEntry : GZipArchiveEntry, IWritableArchiveEntry
+ {
+ private readonly string path;
+ private readonly long size;
+ private readonly DateTime? lastModified;
+ private readonly bool closeStream;
+ private readonly Stream stream;
+
+ internal GZipWritableArchiveEntry(GZipArchive archive, Stream stream,
+ string path, long size, DateTime? lastModified, bool closeStream)
+ : base(archive, null)
+ {
+ this.stream = stream;
+ this.path = path;
+ this.size = size;
+ this.lastModified = lastModified;
+ this.closeStream = closeStream;
+ }
+
+ public override long Crc
+ {
+ get { return 0; }
+ }
+
+ public override string Key
+ {
+ get { return path; }
+ }
+
+ public override long CompressedSize
+ {
+ get { return 0; }
+ }
+
+ public override long Size
+ {
+ get { return size; }
+ }
+
+ public override DateTime? LastModifiedTime
+ {
+ get { return lastModified; }
+ }
+
+ public override DateTime? CreatedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? LastAccessedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? ArchivedTime
+ {
+ get { return null; }
+ }
+
+ public override bool IsEncrypted
+ {
+ get { return false; }
+ }
+
+ public override bool IsDirectory
+ {
+ get { return false; }
+ }
+
+ public override bool IsSplit
+ {
+ get { return false; }
+ }
+
+ internal override IEnumerable Parts
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ Stream IWritableArchiveEntry.Stream
+ {
+ get
+ {
+ return stream;
+ }
+ }
+
+ public override Stream OpenEntryStream()
+ {
+ //ensure new stream is at the start, this could be reset
+ stream.Seek(0, SeekOrigin.Begin);
+ return new NonDisposingStream(stream);
+ }
+
+ internal override void Close()
+ {
+ if (closeStream)
+ {
+ stream.Dispose();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IArchive.Extensions.cs b/src/SharpCompress/Archive/IArchive.Extensions.cs
similarity index 92%
rename from SharpCompress/Archive/IArchive.Extensions.cs
rename to src/SharpCompress/Archive/IArchive.Extensions.cs
index 45638956..d5823d75 100644
--- a/SharpCompress/Archive/IArchive.Extensions.cs
+++ b/src/SharpCompress/Archive/IArchive.Extensions.cs
@@ -1,22 +1,22 @@
-using System.Linq;
-using SharpCompress.Common;
-
-namespace SharpCompress.Archive
-{
- public static class IArchiveExtensions
- {
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Extract to specific directory, retaining filename
- ///
- public static void WriteToDirectory(this IArchive archive, string destinationDirectory,
- ExtractOptions options = ExtractOptions.Overwrite)
- {
- foreach (IArchiveEntry entry in archive.Entries.Where(x => !x.IsDirectory))
- {
- entry.WriteToDirectory(destinationDirectory, options);
- }
- }
-#endif
- }
+using System.Linq;
+using SharpCompress.Common;
+
+namespace SharpCompress.Archive
+{
+ public static class IArchiveExtensions
+ {
+#if !NO_FILE
+ ///
+ /// Extract to specific directory, retaining filename
+ ///
+ public static void WriteToDirectory(this IArchive archive, string destinationDirectory,
+ ExtractOptions options = ExtractOptions.Overwrite)
+ {
+ foreach (IArchiveEntry entry in archive.Entries.Where(x => !x.IsDirectory))
+ {
+ entry.WriteToDirectory(destinationDirectory, options);
+ }
+ }
+#endif
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IArchive.cs b/src/SharpCompress/Archive/IArchive.cs
similarity index 97%
rename from SharpCompress/Archive/IArchive.cs
rename to src/SharpCompress/Archive/IArchive.cs
index c70e49d3..a34f7f9d 100644
--- a/SharpCompress/Archive/IArchive.cs
+++ b/src/SharpCompress/Archive/IArchive.cs
@@ -1,49 +1,49 @@
-using System;
-using System.Collections.Generic;
-using SharpCompress.Common;
-using SharpCompress.Reader;
-
-namespace SharpCompress.Archive
-{
- public interface IArchive : IDisposable
- {
- event EventHandler> EntryExtractionBegin;
- event EventHandler> EntryExtractionEnd;
-
- event EventHandler CompressedBytesRead;
- event EventHandler FilePartExtractionBegin;
-
- IEnumerable Entries { get; }
- IEnumerable Volumes { get; }
-
- ArchiveType Type { get; }
-
- ///
- /// Use this method to extract all entries in an archive in order.
- /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
- /// extracted sequentially for the best performance.
- ///
- IReader ExtractAllEntries();
-
- ///
- /// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
- /// Rar Archives can be SOLID while all 7Zip archives are considered SOLID.
- ///
- bool IsSolid { get; }
-
- ///
- /// This checks to see if all the known entries have IsComplete = true
- ///
- bool IsComplete { get; }
-
- ///
- /// The total size of the files compressed in the archive.
- ///
- long TotalSize { get; }
-
- ///
- /// The total size of the files as uncompressed in the archive.
- ///
- long TotalUncompressSize { get; }
- }
+using System;
+using System.Collections.Generic;
+using SharpCompress.Common;
+using SharpCompress.Reader;
+
+namespace SharpCompress.Archive
+{
+ public interface IArchive : IDisposable
+ {
+ event EventHandler> EntryExtractionBegin;
+ event EventHandler> EntryExtractionEnd;
+
+ event EventHandler CompressedBytesRead;
+ event EventHandler FilePartExtractionBegin;
+
+ IEnumerable Entries { get; }
+ IEnumerable Volumes { get; }
+
+ ArchiveType Type { get; }
+
+ ///
+ /// Use this method to extract all entries in an archive in order.
+ /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
+ /// extracted sequentially for the best performance.
+ ///
+ IReader ExtractAllEntries();
+
+ ///
+ /// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
+ /// Rar Archives can be SOLID while all 7Zip archives are considered SOLID.
+ ///
+ bool IsSolid { get; }
+
+ ///
+ /// This checks to see if all the known entries have IsComplete = true
+ ///
+ bool IsComplete { get; }
+
+ ///
+ /// The total size of the files compressed in the archive.
+ ///
+ long TotalSize { get; }
+
+ ///
+ /// The total size of the files as uncompressed in the archive.
+ ///
+ long TotalUncompressSize { get; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IArchiveEntry.Extensions.cs b/src/SharpCompress/Archive/IArchiveEntry.Extensions.cs
similarity index 96%
rename from SharpCompress/Archive/IArchiveEntry.Extensions.cs
rename to src/SharpCompress/Archive/IArchiveEntry.Extensions.cs
index 239a372c..b84741fc 100644
--- a/SharpCompress/Archive/IArchiveEntry.Extensions.cs
+++ b/src/SharpCompress/Archive/IArchiveEntry.Extensions.cs
@@ -1,90 +1,90 @@
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive
-{
- public static class IArchiveEntryExtensions
- {
- public static void WriteTo(this IArchiveEntry archiveEntry, Stream streamToWriteTo)
- {
- if (archiveEntry.Archive.Type == ArchiveType.Rar && archiveEntry.Archive.IsSolid)
- {
- throw new InvalidFormatException("Cannot use Archive random access on SOLID Rar files.");
- }
-
- if (archiveEntry.IsDirectory)
- {
- throw new ExtractionException("Entry is a file directory and cannot be extracted.");
- }
-
- var streamListener = archiveEntry.Archive as IArchiveExtractionListener;
- streamListener.EnsureEntriesLoaded();
- streamListener.FireEntryExtractionBegin(archiveEntry);
- streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
- var entryStream = archiveEntry.OpenEntryStream();
- if (entryStream == null)
- {
- return;
- }
- using (entryStream)
- using (Stream s = new ListeningStream(streamListener, entryStream))
- {
- s.TransferTo(streamToWriteTo);
- }
- streamListener.FireEntryExtractionEnd(archiveEntry);
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Extract to specific directory, retaining filename
- ///
- public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
- ExtractOptions options = ExtractOptions.Overwrite)
- {
- string destinationFileName;
- string file = Path.GetFileName(entry.Key);
-
-
- if (options.HasFlag(ExtractOptions.ExtractFullPath))
- {
- string folder = Path.GetDirectoryName(entry.Key);
- string destdir = Path.Combine(destinationDirectory, folder);
- if (!Directory.Exists(destdir))
- {
- Directory.CreateDirectory(destdir);
- }
- destinationFileName = Path.Combine(destdir, file);
- }
- else
- {
- destinationFileName = Path.Combine(destinationDirectory, file);
- }
- if (!entry.IsDirectory)
- {
- entry.WriteToFile(destinationFileName, options);
- }
- }
-
- ///
- /// Extract to specific file
- ///
- public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
- ExtractOptions options = ExtractOptions.Overwrite)
- {
- FileMode fm = FileMode.Create;
-
- if (!options.HasFlag(ExtractOptions.Overwrite))
- {
- fm = FileMode.CreateNew;
- }
- using (FileStream fs = File.Open(destinationFileName, fm))
- {
- entry.WriteTo(fs);
- }
-
- entry.PreserveExtractionOptions(destinationFileName, options);
- }
-#endif
- }
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive
+{
+ public static class IArchiveEntryExtensions
+ {
+ public static void WriteTo(this IArchiveEntry archiveEntry, Stream streamToWriteTo)
+ {
+ if (archiveEntry.Archive.Type == ArchiveType.Rar && archiveEntry.Archive.IsSolid)
+ {
+ throw new InvalidFormatException("Cannot use Archive random access on SOLID Rar files.");
+ }
+
+ if (archiveEntry.IsDirectory)
+ {
+ throw new ExtractionException("Entry is a file directory and cannot be extracted.");
+ }
+
+ var streamListener = archiveEntry.Archive as IArchiveExtractionListener;
+ streamListener.EnsureEntriesLoaded();
+ streamListener.FireEntryExtractionBegin(archiveEntry);
+ streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
+ var entryStream = archiveEntry.OpenEntryStream();
+ if (entryStream == null)
+ {
+ return;
+ }
+ using (entryStream)
+ using (Stream s = new ListeningStream(streamListener, entryStream))
+ {
+ s.TransferTo(streamToWriteTo);
+ }
+ streamListener.FireEntryExtractionEnd(archiveEntry);
+ }
+
+#if !NO_FILE
+ ///
+ /// Extract to specific directory, retaining filename
+ ///
+ public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
+ ExtractOptions options = ExtractOptions.Overwrite)
+ {
+ string destinationFileName;
+ string file = Path.GetFileName(entry.Key);
+
+
+ if (options.HasFlag(ExtractOptions.ExtractFullPath))
+ {
+ string folder = Path.GetDirectoryName(entry.Key);
+ string destdir = Path.Combine(destinationDirectory, folder);
+ if (!Directory.Exists(destdir))
+ {
+ Directory.CreateDirectory(destdir);
+ }
+ destinationFileName = Path.Combine(destdir, file);
+ }
+ else
+ {
+ destinationFileName = Path.Combine(destinationDirectory, file);
+ }
+ if (!entry.IsDirectory)
+ {
+ entry.WriteToFile(destinationFileName, options);
+ }
+ }
+
+ ///
+ /// Extract to specific file
+ ///
+ public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
+ ExtractOptions options = ExtractOptions.Overwrite)
+ {
+ FileMode fm = FileMode.Create;
+
+ if (!options.HasFlag(ExtractOptions.Overwrite))
+ {
+ fm = FileMode.CreateNew;
+ }
+ using (FileStream fs = File.Open(destinationFileName, fm))
+ {
+ entry.WriteTo(fs);
+ }
+
+ entry.PreserveExtractionOptions(destinationFileName, options);
+ }
+#endif
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IArchiveEntry.cs b/src/SharpCompress/Archive/IArchiveEntry.cs
similarity index 96%
rename from SharpCompress/Archive/IArchiveEntry.cs
rename to src/SharpCompress/Archive/IArchiveEntry.cs
index b9f04364..ac52485b 100644
--- a/SharpCompress/Archive/IArchiveEntry.cs
+++ b/src/SharpCompress/Archive/IArchiveEntry.cs
@@ -1,24 +1,24 @@
-using System.IO;
-using SharpCompress.Common;
-
-namespace SharpCompress.Archive
-{
- public interface IArchiveEntry : IEntry
- {
- ///
- /// Opens the current entry as a stream that will decompress as it is read.
- /// Read the entire stream or use SkipEntry on EntryStream.
- ///
- Stream OpenEntryStream();
-
- ///
- /// The archive can find all the parts of the archive needed to extract this entry.
- ///
- bool IsComplete { get; }
-
- ///
- /// The archive instance this entry belongs to
- ///
- IArchive Archive { get; }
- }
+using System.IO;
+using SharpCompress.Common;
+
+namespace SharpCompress.Archive
+{
+ public interface IArchiveEntry : IEntry
+ {
+ ///
+ /// Opens the current entry as a stream that will decompress as it is read.
+ /// Read the entire stream or use SkipEntry on EntryStream.
+ ///
+ Stream OpenEntryStream();
+
+ ///
+ /// The archive can find all the parts of the archive needed to extract this entry.
+ ///
+ bool IsComplete { get; }
+
+ ///
+ /// The archive instance this entry belongs to
+ ///
+ IArchive Archive { get; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IArchiveExtractionListener.cs b/src/SharpCompress/Archive/IArchiveExtractionListener.cs
similarity index 96%
rename from SharpCompress/Archive/IArchiveExtractionListener.cs
rename to src/SharpCompress/Archive/IArchiveExtractionListener.cs
index aa15a875..12a1e9ff 100644
--- a/SharpCompress/Archive/IArchiveExtractionListener.cs
+++ b/src/SharpCompress/Archive/IArchiveExtractionListener.cs
@@ -1,11 +1,11 @@
-using SharpCompress.Common;
-
-namespace SharpCompress.Archive
-{
- internal interface IArchiveExtractionListener : IExtractionListener
- {
- void EnsureEntriesLoaded();
- void FireEntryExtractionBegin(IArchiveEntry entry);
- void FireEntryExtractionEnd(IArchiveEntry entry);
- }
+using SharpCompress.Common;
+
+namespace SharpCompress.Archive
+{
+ internal interface IArchiveExtractionListener : IExtractionListener
+ {
+ void EnsureEntriesLoaded();
+ void FireEntryExtractionBegin(IArchiveEntry entry);
+ void FireEntryExtractionEnd(IArchiveEntry entry);
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/IWritableArchive.Extensions.cs b/src/SharpCompress/Archive/IWritableArchive.Extensions.cs
similarity index 99%
rename from SharpCompress/Archive/IWritableArchive.Extensions.cs
rename to src/SharpCompress/Archive/IWritableArchive.Extensions.cs
index 2b577caa..d4ec0f8d 100644
--- a/SharpCompress/Archive/IWritableArchive.Extensions.cs
+++ b/src/SharpCompress/Archive/IWritableArchive.Extensions.cs
@@ -12,7 +12,7 @@ namespace SharpCompress.Archive
writableArchive.SaveTo(stream, new CompressionInfo {Type = compressionType});
}
-#if !PORTABLE && !NETFX_CORE
+#if !NO_FILE
public static void AddEntry(this IWritableArchive writableArchive,
string entryPath, string filePath)
diff --git a/SharpCompress/Archive/IWritableArchive.cs b/src/SharpCompress/Archive/IWritableArchive.cs
similarity index 100%
rename from SharpCompress/Archive/IWritableArchive.cs
rename to src/SharpCompress/Archive/IWritableArchive.cs
diff --git a/SharpCompress/Archive/IWritableArchiveEntry.cs b/src/SharpCompress/Archive/IWritableArchiveEntry.cs
similarity index 94%
rename from SharpCompress/Archive/IWritableArchiveEntry.cs
rename to src/SharpCompress/Archive/IWritableArchiveEntry.cs
index 2175fdae..74ebb935 100644
--- a/SharpCompress/Archive/IWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archive/IWritableArchiveEntry.cs
@@ -1,9 +1,9 @@
-using System.IO;
-
-namespace SharpCompress.Archive
-{
- internal interface IWritableArchiveEntry
- {
- Stream Stream { get; }
- }
+using System.IO;
+
+namespace SharpCompress.Archive
+{
+ internal interface IWritableArchiveEntry
+ {
+ Stream Stream { get; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs b/src/SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs
similarity index 94%
rename from SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs
rename to src/SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs
index 0630f4cf..2404bff3 100644
--- a/SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs
+++ b/src/SharpCompress/Archive/Rar/FileInfoRarArchiveVolume.cs
@@ -1,46 +1,48 @@
-using System.Collections.Generic;
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive.Rar
-{
- ///
- /// A rar part based on a FileInfo object
- ///
- internal class FileInfoRarArchiveVolume : RarVolume
- {
- internal FileInfoRarArchiveVolume(FileInfo fileInfo, string password, Options options)
- : base(StreamingMode.Seekable, fileInfo.OpenRead(), password, FixOptions(options))
- {
- FileInfo = fileInfo;
- FileParts = base.GetVolumeFileParts().ToReadOnly();
- }
-
- private static Options FixOptions(Options options)
- {
- //make sure we're closing streams with fileinfo
- if (options.HasFlag(Options.KeepStreamsOpen))
- {
- options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
- }
- return options;
- }
-
- internal ReadOnlyCollection FileParts { get; private set; }
-
- internal FileInfo FileInfo { get; private set; }
-
- internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
- {
- return new FileInfoRarFilePart(this, markHeader, fileHeader, FileInfo);
- }
-
- internal override IEnumerable ReadFileParts()
- {
- return FileParts;
- }
- }
-}
\ No newline at end of file
+#if !NO_FILE
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive.Rar
+{
+ ///
+ /// A rar part based on a FileInfo object
+ ///
+ internal class FileInfoRarArchiveVolume : RarVolume
+ {
+ internal FileInfoRarArchiveVolume(FileInfo fileInfo, string password, Options options)
+ : base(StreamingMode.Seekable, fileInfo.OpenRead(), password, FixOptions(options))
+ {
+ FileInfo = fileInfo;
+ FileParts = base.GetVolumeFileParts().ToReadOnly();
+ }
+
+ private static Options FixOptions(Options options)
+ {
+ //make sure we're closing streams with fileinfo
+ if (options.HasFlag(Options.KeepStreamsOpen))
+ {
+ options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
+ }
+ return options;
+ }
+
+ internal ReadOnlyCollection FileParts { get; private set; }
+
+ internal FileInfo FileInfo { get; private set; }
+
+ internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
+ {
+ return new FileInfoRarFilePart(this, markHeader, fileHeader, FileInfo);
+ }
+
+ internal override IEnumerable ReadFileParts()
+ {
+ return FileParts;
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs b/src/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
similarity index 93%
rename from SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
rename to src/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
index 8c64e3b3..f018d873 100644
--- a/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
+++ b/src/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
@@ -1,26 +1,28 @@
-using System.IO;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-
-namespace SharpCompress.Archive.Rar
-{
- internal class FileInfoRarFilePart : SeekableFilePart
- {
- internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
- : base(mh, fh, volume.Stream, volume.Password)
- {
- FileInfo = fi;
- }
-
- internal FileInfo FileInfo { get; private set; }
-
- internal override string FilePartName
- {
- get
- {
- return "Rar File: " + FileInfo.FullName
- + " File Entry: " + FileHeader.FileName;
- }
- }
- }
-}
\ No newline at end of file
+#if !NO_FILE
+using System.IO;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+
+namespace SharpCompress.Archive.Rar
+{
+ internal class FileInfoRarFilePart : SeekableFilePart
+ {
+ internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
+ : base(mh, fh, volume.Stream, volume.Password)
+ {
+ FileInfo = fi;
+ }
+
+ internal FileInfo FileInfo { get; private set; }
+
+ internal override string FilePartName
+ {
+ get
+ {
+ return "Rar File: " + FileInfo.FullName
+ + " File Entry: " + FileHeader.FileName;
+ }
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/RarArchive.Extensions.cs b/src/SharpCompress/Archive/Rar/RarArchive.Extensions.cs
similarity index 97%
rename from SharpCompress/Archive/Rar/RarArchive.Extensions.cs
rename to src/SharpCompress/Archive/Rar/RarArchive.Extensions.cs
index bb9d952b..38db8bee 100644
--- a/SharpCompress/Archive/Rar/RarArchive.Extensions.cs
+++ b/src/SharpCompress/Archive/Rar/RarArchive.Extensions.cs
@@ -1,23 +1,23 @@
-using System.Linq;
-
-namespace SharpCompress.Archive.Rar
-{
- public static class RarArchiveExtensions
- {
- ///
- /// RarArchive is the first volume of a multi-part archive. If MultipartVolume is true and IsFirstVolume is false then the first volume file must be missing.
- ///
- public static bool IsFirstVolume(this RarArchive archive)
- {
- return archive.Volumes.First().IsFirstVolume;
- }
-
- ///
- /// RarArchive is part of a multi-part archive.
- ///
- public static bool IsMultipartVolume(this RarArchive archive)
- {
- return archive.Volumes.First().IsMultiVolume;
- }
- }
+using System.Linq;
+
+namespace SharpCompress.Archive.Rar
+{
+ public static class RarArchiveExtensions
+ {
+ ///
+ /// RarArchive is the first volume of a multi-part archive. If MultipartVolume is true and IsFirstVolume is false then the first volume file must be missing.
+ ///
+ public static bool IsFirstVolume(this RarArchive archive)
+ {
+ return archive.Volumes.First().IsFirstVolume;
+ }
+
+ ///
+ /// RarArchive is part of a multi-part archive.
+ ///
+ public static bool IsMultipartVolume(this RarArchive archive)
+ {
+ return archive.Volumes.First().IsMultiVolume;
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/RarArchive.cs b/src/SharpCompress/Archive/Rar/RarArchive.cs
similarity index 95%
rename from SharpCompress/Archive/Rar/RarArchive.cs
rename to src/SharpCompress/Archive/Rar/RarArchive.cs
index 0eff6bc5..a66d5dca 100644
--- a/SharpCompress/Archive/Rar/RarArchive.cs
+++ b/src/SharpCompress/Archive/Rar/RarArchive.cs
@@ -1,166 +1,166 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-using SharpCompress.Compressor.Rar;
-using SharpCompress.IO;
-using SharpCompress.Reader;
-using SharpCompress.Reader.Rar;
-
-namespace SharpCompress.Archive.Rar
-{
- public class RarArchive : AbstractArchive
- {
- private readonly Unpack unpack = new Unpack();
-
- internal Unpack Unpack
- {
- get { return unpack; }
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- ///
- internal RarArchive(FileInfo fileInfo, Options options, string password)
- : base(ArchiveType.Rar, fileInfo, options, password)
- {
- }
-
- protected override IEnumerable LoadVolumes(FileInfo file, Options options)
- {
- return RarArchiveVolumeFactory.GetParts(file, Password, options);
- }
-#endif
-
- ///
- /// Takes multiple seekable Streams for a multi-part archive
- ///
- ///
- ///
- ///
- internal RarArchive(IEnumerable streams, Options options, string password)
- : base(ArchiveType.Rar, streams, options, password)
- {
- }
-
- protected override IEnumerable LoadEntries(IEnumerable volumes)
- {
- return RarArchiveEntryFactory.GetEntries(this, volumes);
- }
-
- protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
- {
- return RarArchiveVolumeFactory.GetParts(streams, Password, options);
- }
-
- protected override IReader CreateReaderForSolidExtraction()
- {
- var stream = Volumes.First().Stream;
- stream.Position = 0;
- return RarReader.Open(stream, Password);
- }
-
- public override bool IsSolid
- {
- get { return Volumes.First().IsSolidArchive; }
- }
-
- #region Creation
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- ///
- public static RarArchive Open(string filePath, Options options = Options.None, string password = null)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options, password);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- ///
- public static RarArchive Open(FileInfo fileInfo, Options options = Options.None, string password = null)
- {
- fileInfo.CheckNotNull("fileInfo");
- return new RarArchive(fileInfo, options, password);
- }
-#endif
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- ///
- public static RarArchive Open(Stream stream, Options options = Options.KeepStreamsOpen, string password = null)
- {
- stream.CheckNotNull("stream");
- return Open(stream.AsEnumerable(), options, password);
- }
-
- ///
- /// Takes multiple seekable Streams for a multi-part archive
- ///
- ///
- ///
- ///
- public static RarArchive Open(IEnumerable streams, Options options = Options.KeepStreamsOpen, string password = null)
- {
- streams.CheckNotNull("streams");
- return new RarArchive(streams, options, password);
- }
-
-#if !PORTABLE && !NETFX_CORE
- public static bool IsRarFile(string filePath)
- {
- return IsRarFile(new FileInfo(filePath));
- }
-
- public static bool IsRarFile(FileInfo fileInfo)
- {
- if (!fileInfo.Exists)
- {
- return false;
- }
- using (Stream stream = fileInfo.OpenRead())
- {
- return IsRarFile(stream);
- }
- }
-#endif
-
- public static bool IsRarFile(Stream stream)
- {
- return IsRarFile(stream, Options.None);
- }
-
- public static bool IsRarFile(Stream stream, Options options)
- {
- try
- {
- var headerFactory = new RarHeaderFactory(StreamingMode.Seekable, options);
- var markHeader = headerFactory.ReadHeaders(stream).FirstOrDefault() as MarkHeader;
- return markHeader != null && markHeader.IsValid();
- }
- catch
- {
- return false;
- }
- }
-
- #endregion
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+using SharpCompress.Compressor.Rar;
+using SharpCompress.IO;
+using SharpCompress.Reader;
+using SharpCompress.Reader.Rar;
+
+namespace SharpCompress.Archive.Rar
+{
+ public class RarArchive : AbstractArchive
+ {
+ private readonly Unpack unpack = new Unpack();
+
+ internal Unpack Unpack
+ {
+ get { return unpack; }
+ }
+
+#if !NO_FILE
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ ///
+ internal RarArchive(FileInfo fileInfo, Options options, string password)
+ : base(ArchiveType.Rar, fileInfo, options, password)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(FileInfo file, Options options)
+ {
+ return RarArchiveVolumeFactory.GetParts(file, Password, options);
+ }
+#endif
+
+ ///
+ /// Takes multiple seekable Streams for a multi-part archive
+ ///
+ ///
+ ///
+ ///
+ internal RarArchive(IEnumerable streams, Options options, string password)
+ : base(ArchiveType.Rar, streams, options, password)
+ {
+ }
+
+ protected override IEnumerable LoadEntries(IEnumerable volumes)
+ {
+ return RarArchiveEntryFactory.GetEntries(this, volumes);
+ }
+
+ protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
+ {
+ return RarArchiveVolumeFactory.GetParts(streams, Password, options);
+ }
+
+ protected override IReader CreateReaderForSolidExtraction()
+ {
+ var stream = Volumes.First().Stream;
+ stream.Position = 0;
+ return RarReader.Open(stream, Password);
+ }
+
+ public override bool IsSolid
+ {
+ get { return Volumes.First().IsSolidArchive; }
+ }
+
+ #region Creation
+
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ ///
+ public static RarArchive Open(string filePath, Options options = Options.None, string password = null)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options, password);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ ///
+ public static RarArchive Open(FileInfo fileInfo, Options options = Options.None, string password = null)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ return new RarArchive(fileInfo, options, password);
+ }
+#endif
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ ///
+ public static RarArchive Open(Stream stream, Options options = Options.KeepStreamsOpen, string password = null)
+ {
+ stream.CheckNotNull("stream");
+ return Open(stream.AsEnumerable(), options, password);
+ }
+
+ ///
+ /// Takes multiple seekable Streams for a multi-part archive
+ ///
+ ///
+ ///
+ ///
+ public static RarArchive Open(IEnumerable streams, Options options = Options.KeepStreamsOpen, string password = null)
+ {
+ streams.CheckNotNull("streams");
+ return new RarArchive(streams, options, password);
+ }
+
+#if !NO_FILE
+ public static bool IsRarFile(string filePath)
+ {
+ return IsRarFile(new FileInfo(filePath));
+ }
+
+ public static bool IsRarFile(FileInfo fileInfo)
+ {
+ if (!fileInfo.Exists)
+ {
+ return false;
+ }
+ using (Stream stream = fileInfo.OpenRead())
+ {
+ return IsRarFile(stream);
+ }
+ }
+#endif
+
+ public static bool IsRarFile(Stream stream)
+ {
+ return IsRarFile(stream, Options.None);
+ }
+
+ public static bool IsRarFile(Stream stream, Options options)
+ {
+ try
+ {
+ var headerFactory = new RarHeaderFactory(StreamingMode.Seekable, options);
+ var markHeader = headerFactory.ReadHeaders(stream).FirstOrDefault() as MarkHeader;
+ return markHeader != null && markHeader.IsValid();
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archive/Rar/RarArchiveEntry.cs
similarity index 96%
rename from SharpCompress/Archive/Rar/RarArchiveEntry.cs
rename to src/SharpCompress/Archive/Rar/RarArchiveEntry.cs
index 9b69100b..c655604b 100644
--- a/SharpCompress/Archive/Rar/RarArchiveEntry.cs
+++ b/src/SharpCompress/Archive/Rar/RarArchiveEntry.cs
@@ -1,97 +1,97 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-using SharpCompress.Compressor.Rar;
-
-namespace SharpCompress.Archive.Rar
-{
- public class RarArchiveEntry : RarEntry, IArchiveEntry
- {
- private readonly ICollection parts;
- private readonly RarArchive archive;
-
- internal RarArchiveEntry(RarArchive archive, IEnumerable parts)
- {
- this.parts = parts.ToList();
- this.archive = archive;
- }
-
- public override CompressionType CompressionType
- {
- get { return CompressionType.Rar; }
- }
-
- public IArchive Archive
- {
- get
- {
- return archive;
- }
- }
-
- internal override IEnumerable Parts
- {
- get { return parts.Cast(); }
- }
-
- internal override FileHeader FileHeader
- {
- get { return parts.First().FileHeader; }
- }
-
- public override long Crc
- {
- get
- {
- CheckIncomplete();
- return parts.Select(fp => fp.FileHeader)
- .Single(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)).FileCRC;
- }
- }
-
-
- public override long Size
- {
- get
- {
- CheckIncomplete();
- return parts.First().FileHeader.UncompressedSize;
- }
- }
-
- public override long CompressedSize
- {
- get
- {
- CheckIncomplete();
- return parts.Aggregate(0L, (total, fp) => { return total + fp.FileHeader.CompressedSize; });
- }
- }
-
- public Stream OpenEntryStream()
- {
- if (archive.IsSolid)
- {
- throw new InvalidOperationException("Use ExtractAllEntries to extract SOLID archives.");
- }
- return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive));
- }
-
- public bool IsComplete
- {
- get { return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)); }
- }
-
- private void CheckIncomplete()
- {
- if (!IsComplete)
- {
- throw new IncompleteArchiveException("ArchiveEntry is incomplete and cannot perform this operation.");
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+using SharpCompress.Compressor.Rar;
+
+namespace SharpCompress.Archive.Rar
+{
+ public class RarArchiveEntry : RarEntry, IArchiveEntry
+ {
+ private readonly ICollection parts;
+ private readonly RarArchive archive;
+
+ internal RarArchiveEntry(RarArchive archive, IEnumerable parts)
+ {
+ this.parts = parts.ToList();
+ this.archive = archive;
+ }
+
+ public override CompressionType CompressionType
+ {
+ get { return CompressionType.Rar; }
+ }
+
+ public IArchive Archive
+ {
+ get
+ {
+ return archive;
+ }
+ }
+
+ internal override IEnumerable Parts
+ {
+ get { return parts.Cast(); }
+ }
+
+ internal override FileHeader FileHeader
+ {
+ get { return parts.First().FileHeader; }
+ }
+
+ public override long Crc
+ {
+ get
+ {
+ CheckIncomplete();
+ return parts.Select(fp => fp.FileHeader)
+ .Single(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)).FileCRC;
+ }
+ }
+
+
+ public override long Size
+ {
+ get
+ {
+ CheckIncomplete();
+ return parts.First().FileHeader.UncompressedSize;
+ }
+ }
+
+ public override long CompressedSize
+ {
+ get
+ {
+ CheckIncomplete();
+ return parts.Aggregate(0L, (total, fp) => { return total + fp.FileHeader.CompressedSize; });
+ }
+ }
+
+ public Stream OpenEntryStream()
+ {
+ if (archive.IsSolid)
+ {
+ throw new InvalidOperationException("Use ExtractAllEntries to extract SOLID archives.");
+ }
+ return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive));
+ }
+
+ public bool IsComplete
+ {
+ get { return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)); }
+ }
+
+ private void CheckIncomplete()
+ {
+ if (!IsComplete)
+ {
+ throw new IncompleteArchiveException("ArchiveEntry is incomplete and cannot perform this operation.");
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs b/src/SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs
similarity index 97%
rename from SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs
rename to src/SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs
index 9f6ca64a..ec55c28d 100644
--- a/SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs
+++ b/src/SharpCompress/Archive/Rar/RarArchiveEntryFactory.cs
@@ -1,49 +1,49 @@
-using System.Collections.Generic;
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-
-namespace SharpCompress.Archive.Rar
-{
- internal static class RarArchiveEntryFactory
- {
- private static IEnumerable GetFileParts(IEnumerable parts)
- {
- foreach (RarVolume rarPart in parts)
- {
- foreach (RarFilePart fp in rarPart.ReadFileParts())
- {
- yield return fp;
- }
- }
- }
-
- private static IEnumerable> GetMatchedFileParts(IEnumerable parts)
- {
- var groupedParts = new List();
- foreach (RarFilePart fp in GetFileParts(parts))
- {
- groupedParts.Add(fp);
-
- if (!FlagUtility.HasFlag((long) fp.FileHeader.FileFlags, (long) FileFlags.SPLIT_AFTER))
- {
- yield return groupedParts;
- groupedParts = new List();
- }
- }
- if (groupedParts.Count > 0)
- {
- yield return groupedParts;
- }
- }
-
- internal static IEnumerable GetEntries(RarArchive archive,
- IEnumerable rarParts)
- {
- foreach (var groupedParts in GetMatchedFileParts(rarParts))
- {
- yield return new RarArchiveEntry(archive, groupedParts);
- }
- }
- }
+using System.Collections.Generic;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+
+namespace SharpCompress.Archive.Rar
+{
+ internal static class RarArchiveEntryFactory
+ {
+ private static IEnumerable GetFileParts(IEnumerable parts)
+ {
+ foreach (RarVolume rarPart in parts)
+ {
+ foreach (RarFilePart fp in rarPart.ReadFileParts())
+ {
+ yield return fp;
+ }
+ }
+ }
+
+ private static IEnumerable> GetMatchedFileParts(IEnumerable parts)
+ {
+ var groupedParts = new List();
+ foreach (RarFilePart fp in GetFileParts(parts))
+ {
+ groupedParts.Add(fp);
+
+ if (!FlagUtility.HasFlag((long) fp.FileHeader.FileFlags, (long) FileFlags.SPLIT_AFTER))
+ {
+ yield return groupedParts;
+ groupedParts = new List();
+ }
+ }
+ if (groupedParts.Count > 0)
+ {
+ yield return groupedParts;
+ }
+ }
+
+ internal static IEnumerable GetEntries(RarArchive archive,
+ IEnumerable rarParts)
+ {
+ foreach (var groupedParts in GetMatchedFileParts(rarParts))
+ {
+ yield return new RarArchiveEntry(archive, groupedParts);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs b/src/SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs
similarity index 95%
rename from SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs
rename to src/SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs
index 3e3a7584..e9ef9a6c 100644
--- a/SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs
+++ b/src/SharpCompress/Archive/Rar/RarArchiveVolumeFactory.cs
@@ -1,147 +1,145 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-#if !PORTABLE
-using System.Linq;
-using System.Text;
-using SharpCompress.Common.Rar.Headers;
-#endif
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-
-namespace SharpCompress.Archive.Rar
-{
- internal static class RarArchiveVolumeFactory
- {
- internal static IEnumerable GetParts(IEnumerable streams, string password, Options options)
- {
- foreach (Stream s in streams)
- {
- if (!s.CanRead || !s.CanSeek)
- {
- throw new ArgumentException("Stream is not readable and seekable");
- }
- StreamRarArchiveVolume part = new StreamRarArchiveVolume(s, password, options);
- yield return part;
- }
- }
-
-#if !PORTABLE && !NETFX_CORE
- internal static IEnumerable GetParts(FileInfo fileInfo, string password, Options options)
- {
- FileInfoRarArchiveVolume part = new FileInfoRarArchiveVolume(fileInfo, password, options);
- yield return part;
-
- if (!part.ArchiveHeader.ArchiveHeaderFlags.HasFlag(ArchiveFlags.VOLUME))
- {
- yield break; //if file isn't volume then there is no reason to look
- }
- ArchiveHeader ah = part.ArchiveHeader;
- fileInfo = GetNextFileInfo(ah, part.FileParts.FirstOrDefault() as FileInfoRarFilePart);
- //we use fileinfo because rar is dumb and looks at file names rather than archive info for another volume
- while (fileInfo != null && fileInfo.Exists)
- {
- part = new FileInfoRarArchiveVolume(fileInfo, password, options);
-
- fileInfo = GetNextFileInfo(ah, part.FileParts.FirstOrDefault() as FileInfoRarFilePart);
- yield return part;
- }
- }
-
- private static FileInfo GetNextFileInfo(ArchiveHeader ah, FileInfoRarFilePart currentFilePart)
- {
- if (currentFilePart == null)
- {
- return null;
- }
- bool oldNumbering = !ah.ArchiveHeaderFlags.HasFlag(ArchiveFlags.NEWNUMBERING)
- || currentFilePart.MarkHeader.OldFormat;
- if (oldNumbering)
- {
- return FindNextFileWithOldNumbering(currentFilePart.FileInfo);
- }
- else
- {
- return FindNextFileWithNewNumbering(currentFilePart.FileInfo);
- }
- }
-
- private static FileInfo FindNextFileWithOldNumbering(FileInfo currentFileInfo)
- {
- // .rar, .r00, .r01, ...
- string extension = currentFileInfo.Extension;
-
- StringBuilder buffer = new StringBuilder(currentFileInfo.FullName.Length);
- buffer.Append(currentFileInfo.FullName.Substring(0,
- currentFileInfo.FullName.Length - extension.Length));
- if (string.Compare(extension, ".rar", StringComparison.InvariantCultureIgnoreCase) == 0)
- {
- buffer.Append(".r00");
- }
- else
- {
- int num = 0;
- if (int.TryParse(extension.Substring(2, 2), out num))
- {
- num++;
- buffer.Append(".r");
- if (num < 10)
- {
- buffer.Append('0');
- }
- buffer.Append(num);
- }
- else
- {
- ThrowInvalidFileName(currentFileInfo);
- }
- }
- return new FileInfo(buffer.ToString());
- }
-
- private static FileInfo FindNextFileWithNewNumbering(FileInfo currentFileInfo)
- {
- // part1.rar, part2.rar, ...
- string extension = currentFileInfo.Extension;
- if (string.Compare(extension, ".rar", StringComparison.InvariantCultureIgnoreCase) != 0)
- {
- throw new ArgumentException("Invalid extension, expected 'rar': " + currentFileInfo.FullName);
- }
- int startIndex = currentFileInfo.FullName.LastIndexOf(".part");
- if (startIndex < 0)
- {
- ThrowInvalidFileName(currentFileInfo);
- }
- StringBuilder buffer = new StringBuilder(currentFileInfo.FullName.Length);
- buffer.Append(currentFileInfo.FullName, 0, startIndex);
- int num = 0;
- string numString = currentFileInfo.FullName.Substring(startIndex + 5,
- currentFileInfo.FullName.IndexOf('.', startIndex + 5) -
- startIndex - 5);
- buffer.Append(".part");
- if (int.TryParse(numString, out num))
- {
- num++;
- for (int i = 0; i < numString.Length - num.ToString().Length; i++)
- {
- buffer.Append('0');
- }
- buffer.Append(num);
- }
- else
- {
- ThrowInvalidFileName(currentFileInfo);
- }
- buffer.Append(".rar");
- return new FileInfo(buffer.ToString());
- }
-
- private static void ThrowInvalidFileName(FileInfo fileInfo)
- {
- throw new ArgumentException("Filename invalid or next archive could not be found:"
- + fileInfo.FullName);
- }
-
-#endif
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using SharpCompress.Common.Rar.Headers;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+
+namespace SharpCompress.Archive.Rar
+{
+ internal static class RarArchiveVolumeFactory
+ {
+ internal static IEnumerable GetParts(IEnumerable streams, string password, Options options)
+ {
+ foreach (Stream s in streams)
+ {
+ if (!s.CanRead || !s.CanSeek)
+ {
+ throw new ArgumentException("Stream is not readable and seekable");
+ }
+ StreamRarArchiveVolume part = new StreamRarArchiveVolume(s, password, options);
+ yield return part;
+ }
+ }
+
+#if !NO_FILE
+ internal static IEnumerable GetParts(FileInfo fileInfo, string password, Options options)
+ {
+ FileInfoRarArchiveVolume part = new FileInfoRarArchiveVolume(fileInfo, password, options);
+ yield return part;
+
+ if (!part.ArchiveHeader.ArchiveHeaderFlags.HasFlag(ArchiveFlags.VOLUME))
+ {
+ yield break; //if file isn't volume then there is no reason to look
+ }
+ ArchiveHeader ah = part.ArchiveHeader;
+ fileInfo = GetNextFileInfo(ah, part.FileParts.FirstOrDefault() as FileInfoRarFilePart);
+ //we use fileinfo because rar is dumb and looks at file names rather than archive info for another volume
+ while (fileInfo != null && fileInfo.Exists)
+ {
+ part = new FileInfoRarArchiveVolume(fileInfo, password, options);
+
+ fileInfo = GetNextFileInfo(ah, part.FileParts.FirstOrDefault() as FileInfoRarFilePart);
+ yield return part;
+ }
+ }
+
+ private static FileInfo GetNextFileInfo(ArchiveHeader ah, FileInfoRarFilePart currentFilePart)
+ {
+ if (currentFilePart == null)
+ {
+ return null;
+ }
+ bool oldNumbering = !ah.ArchiveHeaderFlags.HasFlag(ArchiveFlags.NEWNUMBERING)
+ || currentFilePart.MarkHeader.OldFormat;
+ if (oldNumbering)
+ {
+ return FindNextFileWithOldNumbering(currentFilePart.FileInfo);
+ }
+ else
+ {
+ return FindNextFileWithNewNumbering(currentFilePart.FileInfo);
+ }
+ }
+
+ private static FileInfo FindNextFileWithOldNumbering(FileInfo currentFileInfo)
+ {
+ // .rar, .r00, .r01, ...
+ string extension = currentFileInfo.Extension;
+
+ StringBuilder buffer = new StringBuilder(currentFileInfo.FullName.Length);
+ buffer.Append(currentFileInfo.FullName.Substring(0,
+ currentFileInfo.FullName.Length - extension.Length));
+ if (string.Compare(extension, ".rar", StringComparison.OrdinalIgnoreCase) == 0)
+ {
+ buffer.Append(".r00");
+ }
+ else
+ {
+ int num = 0;
+ if (int.TryParse(extension.Substring(2, 2), out num))
+ {
+ num++;
+ buffer.Append(".r");
+ if (num < 10)
+ {
+ buffer.Append('0');
+ }
+ buffer.Append(num);
+ }
+ else
+ {
+ ThrowInvalidFileName(currentFileInfo);
+ }
+ }
+ return new FileInfo(buffer.ToString());
+ }
+
+ private static FileInfo FindNextFileWithNewNumbering(FileInfo currentFileInfo)
+ {
+ // part1.rar, part2.rar, ...
+ string extension = currentFileInfo.Extension;
+ if (string.Compare(extension, ".rar", StringComparison.OrdinalIgnoreCase) != 0)
+ {
+ throw new ArgumentException("Invalid extension, expected 'rar': " + currentFileInfo.FullName);
+ }
+ int startIndex = currentFileInfo.FullName.LastIndexOf(".part");
+ if (startIndex < 0)
+ {
+ ThrowInvalidFileName(currentFileInfo);
+ }
+ StringBuilder buffer = new StringBuilder(currentFileInfo.FullName.Length);
+ buffer.Append(currentFileInfo.FullName, 0, startIndex);
+ int num = 0;
+ string numString = currentFileInfo.FullName.Substring(startIndex + 5,
+ currentFileInfo.FullName.IndexOf('.', startIndex + 5) -
+ startIndex - 5);
+ buffer.Append(".part");
+ if (int.TryParse(numString, out num))
+ {
+ num++;
+ for (int i = 0; i < numString.Length - num.ToString().Length; i++)
+ {
+ buffer.Append('0');
+ }
+ buffer.Append(num);
+ }
+ else
+ {
+ ThrowInvalidFileName(currentFileInfo);
+ }
+ buffer.Append(".rar");
+ return new FileInfo(buffer.ToString());
+ }
+
+ private static void ThrowInvalidFileName(FileInfo fileInfo)
+ {
+ throw new ArgumentException("Filename invalid or next archive could not be found:"
+ + fileInfo.FullName);
+ }
+
+#endif
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/SeekableFilePart.cs b/src/SharpCompress/Archive/Rar/SeekableFilePart.cs
similarity index 85%
rename from SharpCompress/Archive/Rar/SeekableFilePart.cs
rename to src/SharpCompress/Archive/Rar/SeekableFilePart.cs
index 268e24cc..f052f22a 100644
--- a/SharpCompress/Archive/Rar/SeekableFilePart.cs
+++ b/src/SharpCompress/Archive/Rar/SeekableFilePart.cs
@@ -1,39 +1,37 @@
-using System;
-using System.IO;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-
-namespace SharpCompress.Archive.Rar
-{
- internal class SeekableFilePart : RarFilePart
- {
- private readonly Stream stream;
- private readonly string password;
-
- internal SeekableFilePart(MarkHeader mh, FileHeader fh, Stream stream, string password)
- : base(mh, fh)
- {
- this.stream = stream;
- this.password = password;
- }
-
- internal override Stream GetCompressedStream()
- {
- stream.Position = FileHeader.DataStartPosition;
- if (FileHeader.Salt != null)
- {
-#if PORTABLE
- throw new NotSupportedException("Encrypted Rar files aren't supported in portable distro.");
-#else
- return new RarCryptoWrapper(stream, password, FileHeader.Salt);
-#endif
- }
- return stream;
- }
-
- internal override string FilePartName
- {
- get { return "Unknown Stream - File Entry: " + FileHeader.FileName; }
- }
- }
+using System;
+using System.IO;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+
+namespace SharpCompress.Archive.Rar
+{
+ internal class SeekableFilePart : RarFilePart
+ {
+ private readonly Stream stream;
+ private readonly string password;
+
+ internal SeekableFilePart(MarkHeader mh, FileHeader fh, Stream stream, string password)
+ : base(mh, fh)
+ {
+ this.stream = stream;
+ this.password = password;
+ }
+
+ internal override Stream GetCompressedStream()
+ {
+ stream.Position = FileHeader.DataStartPosition;
+#if !NO_CRYPTO
+ if (FileHeader.Salt != null)
+ {
+ return new RarCryptoWrapper(stream, password, FileHeader.Salt);
+ }
+#endif
+ return stream;
+ }
+
+ internal override string FilePartName
+ {
+ get { return "Unknown Stream - File Entry: " + FileHeader.FileName; }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs b/src/SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs
similarity index 96%
rename from SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs
rename to src/SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs
index d33ffdd8..3b499f12 100644
--- a/SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs
+++ b/src/SharpCompress/Archive/Rar/StreamRarArchiveVolume.cs
@@ -1,27 +1,27 @@
-using System.Collections.Generic;
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.Common.Rar;
-using SharpCompress.Common.Rar.Headers;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive.Rar
-{
- internal class StreamRarArchiveVolume : RarVolume
- {
- internal StreamRarArchiveVolume(Stream stream, string password, Options options)
- : base(StreamingMode.Seekable, stream, password, options)
- {
- }
-
- internal override IEnumerable ReadFileParts()
- {
- return GetVolumeFileParts();
- }
-
- internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
- {
- return new SeekableFilePart(markHeader, fileHeader, Stream, Password);
- }
- }
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.Common.Rar;
+using SharpCompress.Common.Rar.Headers;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive.Rar
+{
+ internal class StreamRarArchiveVolume : RarVolume
+ {
+ internal StreamRarArchiveVolume(Stream stream, string password, Options options)
+ : base(StreamingMode.Seekable, stream, password, options)
+ {
+ }
+
+ internal override IEnumerable ReadFileParts()
+ {
+ return GetVolumeFileParts();
+ }
+
+ internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
+ {
+ return new SeekableFilePart(markHeader, fileHeader, Stream, Password);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archive/SevenZip/SevenZipArchive.cs
similarity index 96%
rename from SharpCompress/Archive/SevenZip/SevenZipArchive.cs
rename to src/SharpCompress/Archive/SevenZip/SevenZipArchive.cs
index a61af62c..73711721 100644
--- a/SharpCompress/Archive/SevenZip/SevenZipArchive.cs
+++ b/src/SharpCompress/Archive/SevenZip/SevenZipArchive.cs
@@ -1,252 +1,252 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.SevenZip;
-using SharpCompress.IO;
-using SharpCompress.Reader;
-
-namespace SharpCompress.Archive.SevenZip
-{
- public class SevenZipArchive : AbstractArchive
- {
- private ArchiveDatabase database;
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- public static SevenZipArchive Open(string filePath)
- {
- return Open(filePath, Options.None);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- public static SevenZipArchive Open(FileInfo fileInfo)
- {
- return Open(fileInfo, Options.None);
- }
-
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- public static SevenZipArchive Open(string filePath, Options options)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- public static SevenZipArchive Open(FileInfo fileInfo, Options options)
- {
- fileInfo.CheckNotNull("fileInfo");
- return new SevenZipArchive(fileInfo, options);
- }
-#endif
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- public static SevenZipArchive Open(Stream stream)
- {
- stream.CheckNotNull("stream");
- return Open(stream, Options.None);
- }
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- public static SevenZipArchive Open(Stream stream, Options options)
- {
- stream.CheckNotNull("stream");
- return new SevenZipArchive(stream, options);
- }
-
-#if !PORTABLE && !NETFX_CORE
- internal SevenZipArchive(FileInfo fileInfo, Options options)
- : base(ArchiveType.SevenZip, fileInfo, options, null)
- {
- }
-
- protected override IEnumerable LoadVolumes(FileInfo file, Options options)
- {
- if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
- {
- options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
- }
- return new SevenZipVolume(file.OpenRead(), options).AsEnumerable();
- }
-
- public static bool IsSevenZipFile(string filePath)
- {
- return IsSevenZipFile(new FileInfo(filePath));
- }
-
- public static bool IsSevenZipFile(FileInfo fileInfo)
- {
- if (!fileInfo.Exists)
- {
- return false;
- }
- using (Stream stream = fileInfo.OpenRead())
- {
- return IsSevenZipFile(stream);
- }
- }
-#endif
-
- internal SevenZipArchive(Stream stream, Options options)
- : base(ArchiveType.SevenZip, stream.AsEnumerable(), options, null)
- {
- }
-
- internal SevenZipArchive()
- : base(ArchiveType.SevenZip)
- {
- }
-
- protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
- {
- foreach (Stream s in streams)
- {
- if (!s.CanRead || !s.CanSeek)
- {
- throw new ArgumentException("Stream is not readable and seekable");
- }
- SevenZipVolume volume = new SevenZipVolume(s, options);
- yield return volume;
- }
- }
-
- protected override IEnumerable LoadEntries(IEnumerable volumes)
- {
- var stream = volumes.Single().Stream;
- LoadFactory(stream);
- for (int i = 0; i < database.Files.Count; i++)
- {
- var file = database.Files[i];
- if (!file.IsDir)
- {
- yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file));
- }
- }
- }
-
- private void LoadFactory(Stream stream)
- {
- if (database == null)
- {
- stream.Position = 0;
- var reader = new ArchiveReader();
- reader.Open(stream);
- database = reader.ReadDatabase(null);
- }
- }
-
-
- public static bool IsSevenZipFile(Stream stream)
- {
- try
- {
- return SignatureMatch(stream);
- }
- catch
- {
- return false;
- }
- }
-
- private static readonly byte[] SIGNATURE = new byte[] {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
-
- private static bool SignatureMatch(Stream stream)
- {
- BinaryReader reader = new BinaryReader(stream);
- byte[] signatureBytes = reader.ReadBytes(6);
- return signatureBytes.BinaryEquals(SIGNATURE);
- }
-
- protected override IReader CreateReaderForSolidExtraction()
- {
- return new SevenZipReader(this);
- }
-
- public override bool IsSolid
- {
- get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; }
- }
-
- public override long TotalSize
- {
- get
- {
- int i = Entries.Count;
- return database.PackSizes.Aggregate(0L, (total, packSize) => total + packSize);
- }
- }
-
- private class SevenZipReader : AbstractReader
- {
- private readonly SevenZipArchive archive;
- private CFolder currentFolder;
- private Stream currentStream;
- private CFileItem currentItem;
-
- internal SevenZipReader(SevenZipArchive archive)
- : base(Options.KeepStreamsOpen, ArchiveType.SevenZip)
- {
- this.archive = archive;
- }
-
-
- public override SevenZipVolume Volume
- {
- get { return archive.Volumes.Single(); }
- }
-
- internal override IEnumerable GetEntries(Stream stream)
- {
- List entries = archive.Entries.ToList();
- stream.Position = 0;
- foreach (var dir in entries.Where(x => x.IsDirectory))
- {
- yield return dir;
- }
- foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder))
- {
- currentFolder = group.Key;
- if (group.Key == null)
- {
- currentStream = Stream.Null;
- }
- else
- {
- currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
- }
- foreach (var entry in group)
- {
- currentItem = entry.FilePart.Header;
- yield return entry;
- }
- }
- }
-
- protected override EntryStream GetEntryStream()
- {
- return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.SevenZip;
+using SharpCompress.IO;
+using SharpCompress.Reader;
+
+namespace SharpCompress.Archive.SevenZip
+{
+ public class SevenZipArchive : AbstractArchive
+ {
+ private ArchiveDatabase database;
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ public static SevenZipArchive Open(string filePath)
+ {
+ return Open(filePath, Options.None);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ public static SevenZipArchive Open(FileInfo fileInfo)
+ {
+ return Open(fileInfo, Options.None);
+ }
+
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ public static SevenZipArchive Open(string filePath, Options options)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ public static SevenZipArchive Open(FileInfo fileInfo, Options options)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ return new SevenZipArchive(fileInfo, options);
+ }
+#endif
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ public static SevenZipArchive Open(Stream stream)
+ {
+ stream.CheckNotNull("stream");
+ return Open(stream, Options.None);
+ }
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ public static SevenZipArchive Open(Stream stream, Options options)
+ {
+ stream.CheckNotNull("stream");
+ return new SevenZipArchive(stream, options);
+ }
+
+#if !NO_FILE
+ internal SevenZipArchive(FileInfo fileInfo, Options options)
+ : base(ArchiveType.SevenZip, fileInfo, options, null)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(FileInfo file, Options options)
+ {
+ if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
+ {
+ options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
+ }
+ return new SevenZipVolume(file.OpenRead(), options).AsEnumerable();
+ }
+
+ public static bool IsSevenZipFile(string filePath)
+ {
+ return IsSevenZipFile(new FileInfo(filePath));
+ }
+
+ public static bool IsSevenZipFile(FileInfo fileInfo)
+ {
+ if (!fileInfo.Exists)
+ {
+ return false;
+ }
+ using (Stream stream = fileInfo.OpenRead())
+ {
+ return IsSevenZipFile(stream);
+ }
+ }
+#endif
+
+ internal SevenZipArchive(Stream stream, Options options)
+ : base(ArchiveType.SevenZip, stream.AsEnumerable(), options, null)
+ {
+ }
+
+ internal SevenZipArchive()
+ : base(ArchiveType.SevenZip)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
+ {
+ foreach (Stream s in streams)
+ {
+ if (!s.CanRead || !s.CanSeek)
+ {
+ throw new ArgumentException("Stream is not readable and seekable");
+ }
+ SevenZipVolume volume = new SevenZipVolume(s, options);
+ yield return volume;
+ }
+ }
+
+ protected override IEnumerable LoadEntries(IEnumerable volumes)
+ {
+ var stream = volumes.Single().Stream;
+ LoadFactory(stream);
+ for (int i = 0; i < database.Files.Count; i++)
+ {
+ var file = database.Files[i];
+ if (!file.IsDir)
+ {
+ yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file));
+ }
+ }
+ }
+
+ private void LoadFactory(Stream stream)
+ {
+ if (database == null)
+ {
+ stream.Position = 0;
+ var reader = new ArchiveReader();
+ reader.Open(stream);
+ database = reader.ReadDatabase(null);
+ }
+ }
+
+
+ public static bool IsSevenZipFile(Stream stream)
+ {
+ try
+ {
+ return SignatureMatch(stream);
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ private static readonly byte[] SIGNATURE = new byte[] {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
+
+ private static bool SignatureMatch(Stream stream)
+ {
+ BinaryReader reader = new BinaryReader(stream);
+ byte[] signatureBytes = reader.ReadBytes(6);
+ return signatureBytes.BinaryEquals(SIGNATURE);
+ }
+
+ protected override IReader CreateReaderForSolidExtraction()
+ {
+ return new SevenZipReader(this);
+ }
+
+ public override bool IsSolid
+ {
+ get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; }
+ }
+
+ public override long TotalSize
+ {
+ get
+ {
+ int i = Entries.Count;
+ return database.PackSizes.Aggregate(0L, (total, packSize) => total + packSize);
+ }
+ }
+
+ private class SevenZipReader : AbstractReader
+ {
+ private readonly SevenZipArchive archive;
+ private CFolder currentFolder;
+ private Stream currentStream;
+ private CFileItem currentItem;
+
+ internal SevenZipReader(SevenZipArchive archive)
+ : base(Options.KeepStreamsOpen, ArchiveType.SevenZip)
+ {
+ this.archive = archive;
+ }
+
+
+ public override SevenZipVolume Volume
+ {
+ get { return archive.Volumes.Single(); }
+ }
+
+ internal override IEnumerable GetEntries(Stream stream)
+ {
+ List entries = archive.Entries.ToList();
+ stream.Position = 0;
+ foreach (var dir in entries.Where(x => x.IsDirectory))
+ {
+ yield return dir;
+ }
+ foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder))
+ {
+ currentFolder = group.Key;
+ if (group.Key == null)
+ {
+ currentStream = Stream.Null;
+ }
+ else
+ {
+ currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
+ }
+ foreach (var entry in group)
+ {
+ currentItem = entry.FilePart.Header;
+ yield return entry;
+ }
+ }
+ }
+
+ protected override EntryStream GetEntryStream()
+ {
+ return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
similarity index 95%
rename from SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
rename to src/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
index c5c2aaba..24eb07d6 100644
--- a/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
+++ b/src/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
@@ -1,34 +1,34 @@
-using System;
-using System.IO;
-using SharpCompress.Common.SevenZip;
-
-namespace SharpCompress.Archive.SevenZip
-{
- public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry
- {
- internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part)
- : base(part)
- {
- Archive = archive;
- }
-
- public Stream OpenEntryStream()
- {
- return FilePart.GetCompressedStream();
- }
- public IArchive Archive { get; private set; }
-
- public bool IsComplete
- {
- get { return true; }
- }
-
- ///
- /// This is a 7Zip Anti item
- ///
- public bool IsAnti
- {
- get { return FilePart.Header.IsAnti; }
- }
- }
+using System;
+using System.IO;
+using SharpCompress.Common.SevenZip;
+
+namespace SharpCompress.Archive.SevenZip
+{
+ public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry
+ {
+ internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part)
+ : base(part)
+ {
+ Archive = archive;
+ }
+
+ public Stream OpenEntryStream()
+ {
+ return FilePart.GetCompressedStream();
+ }
+ public IArchive Archive { get; private set; }
+
+ public bool IsComplete
+ {
+ get { return true; }
+ }
+
+ ///
+ /// This is a 7Zip Anti item
+ ///
+ public bool IsAnti
+ {
+ get { return FilePart.Header.IsAnti; }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Tar/TarArchive.cs b/src/SharpCompress/Archive/Tar/TarArchive.cs
similarity index 96%
rename from SharpCompress/Archive/Tar/TarArchive.cs
rename to src/SharpCompress/Archive/Tar/TarArchive.cs
index 4258a37e..57b2a0b7 100644
--- a/SharpCompress/Archive/Tar/TarArchive.cs
+++ b/src/SharpCompress/Archive/Tar/TarArchive.cs
@@ -1,231 +1,231 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.Tar;
-using SharpCompress.Common.Tar.Headers;
-using SharpCompress.IO;
-using SharpCompress.Reader;
-using SharpCompress.Reader.Tar;
-using SharpCompress.Writer.Tar;
-
-namespace SharpCompress.Archive.Tar
-{
- public class TarArchive : AbstractWritableArchive
- {
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- public static TarArchive Open(string filePath)
- {
- return Open(filePath, Options.None);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- public static TarArchive Open(FileInfo fileInfo)
- {
- return Open(fileInfo, Options.None);
- }
-
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- public static TarArchive Open(string filePath, Options options)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- public static TarArchive Open(FileInfo fileInfo, Options options)
- {
- fileInfo.CheckNotNull("fileInfo");
- return new TarArchive(fileInfo, options);
- }
-#endif
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- public static TarArchive Open(Stream stream)
- {
- stream.CheckNotNull("stream");
- return Open(stream, Options.None);
- }
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- public static TarArchive Open(Stream stream, Options options)
- {
- stream.CheckNotNull("stream");
- return new TarArchive(stream, options);
- }
-
-#if !PORTABLE && !NETFX_CORE
- public static bool IsTarFile(string filePath)
- {
- return IsTarFile(new FileInfo(filePath));
- }
-
- public static bool IsTarFile(FileInfo fileInfo)
- {
- if (!fileInfo.Exists)
- {
- return false;
- }
- using (Stream stream = fileInfo.OpenRead())
- {
- return IsTarFile(stream);
- }
- }
-#endif
-
- public static bool IsTarFile(Stream stream)
- {
- try
- {
- TarHeader tar = new TarHeader();
- tar.Read(new BinaryReader(stream));
- return tar.Name.Length > 0 && Enum.IsDefined(typeof (EntryType), tar.EntryType);
- }
- catch
- {
- }
- return false;
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- internal TarArchive(FileInfo fileInfo, Options options)
- : base(ArchiveType.Tar, fileInfo, options)
- {
- }
-
- protected override IEnumerable LoadVolumes(FileInfo file, Options options)
- {
- if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
- {
- options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
- }
- return new TarVolume(file.OpenRead(), options).AsEnumerable();
- }
-#endif
-
- ///
- /// Takes multiple seekable Streams for a multi-part archive
- ///
- ///
- ///
- internal TarArchive(Stream stream, Options options)
- : base(ArchiveType.Tar, stream, options)
- {
- }
-
- internal TarArchive()
- : base(ArchiveType.Tar)
- {
- }
-
- protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
- {
- return new TarVolume(streams.First(), options).AsEnumerable();
- }
-
- protected override IEnumerable LoadEntries(IEnumerable volumes)
- {
- Stream stream = volumes.Single().Stream;
- TarHeader previousHeader = null;
- foreach (TarHeader header in TarHeaderFactory.ReadHeader(StreamingMode.Seekable, stream))
- {
- if (header != null)
- {
- if (header.EntryType == EntryType.LongName)
- {
- previousHeader = header;
- }
- else
- {
- if (previousHeader != null)
- {
- var entry = new TarArchiveEntry(this, new TarFilePart(previousHeader, stream),
- CompressionType.None);
-
- var oldStreamPos = stream.Position;
-
- using(var entryStream = entry.OpenEntryStream())
- using(var memoryStream = new MemoryStream())
- {
- entryStream.TransferTo(memoryStream);
- memoryStream.Position = 0;
- var bytes = memoryStream.ToArray();
-
- header.Name = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length).TrimNulls();
- }
-
- stream.Position = oldStreamPos;
-
- previousHeader = null;
- }
- yield return new TarArchiveEntry(this, new TarFilePart(header, stream), CompressionType.None);
- }
- }
- }
- }
-
- public static TarArchive Create()
- {
- return new TarArchive();
- }
-
- protected override TarArchiveEntry CreateEntryInternal(string filePath, Stream source,
- long size, DateTime? modified, bool closeStream)
- {
- return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified,
- closeStream);
- }
-
- protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
- IEnumerable oldEntries,
- IEnumerable newEntries)
- {
- using (var writer = new TarWriter(stream, compressionInfo))
- {
- foreach (var entry in oldEntries.Concat(newEntries)
- .Where(x => !x.IsDirectory))
- {
- using (var entryStream = entry.OpenEntryStream())
- {
- writer.Write(entry.Key, entryStream, entry.LastModifiedTime, entry.Size);
- }
- }
- }
- }
-
- protected override IReader CreateReaderForSolidExtraction()
- {
- var stream = Volumes.Single().Stream;
- stream.Position = 0;
- return TarReader.Open(stream);
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.Tar;
+using SharpCompress.Common.Tar.Headers;
+using SharpCompress.IO;
+using SharpCompress.Reader;
+using SharpCompress.Reader.Tar;
+using SharpCompress.Writer.Tar;
+
+namespace SharpCompress.Archive.Tar
+{
+ public class TarArchive : AbstractWritableArchive
+ {
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ public static TarArchive Open(string filePath)
+ {
+ return Open(filePath, Options.None);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ public static TarArchive Open(FileInfo fileInfo)
+ {
+ return Open(fileInfo, Options.None);
+ }
+
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ public static TarArchive Open(string filePath, Options options)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ public static TarArchive Open(FileInfo fileInfo, Options options)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ return new TarArchive(fileInfo, options);
+ }
+#endif
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ public static TarArchive Open(Stream stream)
+ {
+ stream.CheckNotNull("stream");
+ return Open(stream, Options.None);
+ }
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ public static TarArchive Open(Stream stream, Options options)
+ {
+ stream.CheckNotNull("stream");
+ return new TarArchive(stream, options);
+ }
+
+#if !NO_FILE
+ public static bool IsTarFile(string filePath)
+ {
+ return IsTarFile(new FileInfo(filePath));
+ }
+
+ public static bool IsTarFile(FileInfo fileInfo)
+ {
+ if (!fileInfo.Exists)
+ {
+ return false;
+ }
+ using (Stream stream = fileInfo.OpenRead())
+ {
+ return IsTarFile(stream);
+ }
+ }
+#endif
+
+ public static bool IsTarFile(Stream stream)
+ {
+ try
+ {
+ TarHeader tar = new TarHeader();
+ tar.Read(new BinaryReader(stream));
+ return tar.Name.Length > 0 && Enum.IsDefined(typeof (EntryType), tar.EntryType);
+ }
+ catch
+ {
+ }
+ return false;
+ }
+
+#if !NO_FILE
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ internal TarArchive(FileInfo fileInfo, Options options)
+ : base(ArchiveType.Tar, fileInfo, options)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(FileInfo file, Options options)
+ {
+ if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
+ {
+ options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
+ }
+ return new TarVolume(file.OpenRead(), options).AsEnumerable();
+ }
+#endif
+
+ ///
+ /// Takes multiple seekable Streams for a multi-part archive
+ ///
+ ///
+ ///
+ internal TarArchive(Stream stream, Options options)
+ : base(ArchiveType.Tar, stream, options)
+ {
+ }
+
+ internal TarArchive()
+ : base(ArchiveType.Tar)
+ {
+ }
+
+ protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
+ {
+ return new TarVolume(streams.First(), options).AsEnumerable();
+ }
+
+ protected override IEnumerable LoadEntries(IEnumerable volumes)
+ {
+ Stream stream = volumes.Single().Stream;
+ TarHeader previousHeader = null;
+ foreach (TarHeader header in TarHeaderFactory.ReadHeader(StreamingMode.Seekable, stream))
+ {
+ if (header != null)
+ {
+ if (header.EntryType == EntryType.LongName)
+ {
+ previousHeader = header;
+ }
+ else
+ {
+ if (previousHeader != null)
+ {
+ var entry = new TarArchiveEntry(this, new TarFilePart(previousHeader, stream),
+ CompressionType.None);
+
+ var oldStreamPos = stream.Position;
+
+ using(var entryStream = entry.OpenEntryStream())
+ using(var memoryStream = new MemoryStream())
+ {
+ entryStream.TransferTo(memoryStream);
+ memoryStream.Position = 0;
+ var bytes = memoryStream.ToArray();
+
+ header.Name = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length).TrimNulls();
+ }
+
+ stream.Position = oldStreamPos;
+
+ previousHeader = null;
+ }
+ yield return new TarArchiveEntry(this, new TarFilePart(header, stream), CompressionType.None);
+ }
+ }
+ }
+ }
+
+ public static TarArchive Create()
+ {
+ return new TarArchive();
+ }
+
+ protected override TarArchiveEntry CreateEntryInternal(string filePath, Stream source,
+ long size, DateTime? modified, bool closeStream)
+ {
+ return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified,
+ closeStream);
+ }
+
+ protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
+ IEnumerable oldEntries,
+ IEnumerable newEntries)
+ {
+ using (var writer = new TarWriter(stream, compressionInfo))
+ {
+ foreach (var entry in oldEntries.Concat(newEntries)
+ .Where(x => !x.IsDirectory))
+ {
+ using (var entryStream = entry.OpenEntryStream())
+ {
+ writer.Write(entry.Key, entryStream, entry.LastModifiedTime, entry.Size);
+ }
+ }
+ }
+ }
+
+ protected override IReader CreateReaderForSolidExtraction()
+ {
+ var stream = Volumes.Single().Stream;
+ stream.Position = 0;
+ return TarReader.Open(stream);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Tar/TarArchiveEntry.cs b/src/SharpCompress/Archive/Tar/TarArchiveEntry.cs
similarity index 96%
rename from SharpCompress/Archive/Tar/TarArchiveEntry.cs
rename to src/SharpCompress/Archive/Tar/TarArchiveEntry.cs
index cf07aad4..16585964 100644
--- a/SharpCompress/Archive/Tar/TarArchiveEntry.cs
+++ b/src/SharpCompress/Archive/Tar/TarArchiveEntry.cs
@@ -1,31 +1,31 @@
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.Tar;
-
-namespace SharpCompress.Archive.Tar
-{
- public class TarArchiveEntry : TarEntry, IArchiveEntry
- {
- internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType)
- : base(part, compressionType)
- {
- Archive = archive;
- }
-
- public virtual Stream OpenEntryStream()
- {
- return Parts.Single().GetCompressedStream();
- }
-
- #region IArchiveEntry Members
- public IArchive Archive { get; private set; }
-
- public bool IsComplete
- {
- get { return true; }
- }
-
- #endregion
- }
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.Tar;
+
+namespace SharpCompress.Archive.Tar
+{
+ public class TarArchiveEntry : TarEntry, IArchiveEntry
+ {
+ internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType)
+ : base(part, compressionType)
+ {
+ Archive = archive;
+ }
+
+ public virtual Stream OpenEntryStream()
+ {
+ return Parts.Single().GetCompressedStream();
+ }
+
+ #region IArchiveEntry Members
+ public IArchive Archive { get; private set; }
+
+ public bool IsComplete
+ {
+ get { return true; }
+ }
+
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs b/src/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs
similarity index 96%
rename from SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs
rename to src/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs
index b1b1d608..5830fb68 100644
--- a/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs
@@ -1,110 +1,110 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive.Tar
-{
- internal class TarWritableArchiveEntry : TarArchiveEntry, IWritableArchiveEntry
- {
- private readonly string path;
- private readonly long size;
- private readonly DateTime? lastModified;
- private readonly bool closeStream;
- private readonly Stream stream;
-
- internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType,
- string path, long size, DateTime? lastModified, bool closeStream)
- : base(archive, null, compressionType)
- {
- this.stream = stream;
- this.path = path;
- this.size = size;
- this.lastModified = lastModified;
- this.closeStream = closeStream;
- }
-
- public override long Crc
- {
- get { return 0; }
- }
-
- public override string Key
- {
- get { return path; }
- }
-
- public override long CompressedSize
- {
- get { return 0; }
- }
-
- public override long Size
- {
- get { return size; }
- }
-
- public override DateTime? LastModifiedTime
- {
- get { return lastModified; }
- }
-
- public override DateTime? CreatedTime
- {
- get { return null; }
- }
-
- public override DateTime? LastAccessedTime
- {
- get { return null; }
- }
-
- public override DateTime? ArchivedTime
- {
- get { return null; }
- }
-
- public override bool IsEncrypted
- {
- get { return false; }
- }
-
- public override bool IsDirectory
- {
- get { return false; }
- }
-
- public override bool IsSplit
- {
- get { return false; }
- }
-
- internal override IEnumerable Parts
- {
- get { throw new NotImplementedException(); }
- }
- Stream IWritableArchiveEntry.Stream
- {
- get
- {
- return stream;
- }
- }
-
- public override Stream OpenEntryStream()
- {
- //ensure new stream is at the start, this could be reset
- stream.Seek(0, SeekOrigin.Begin);
- return new NonDisposingStream(stream);
- }
-
- internal override void Close()
- {
- if (closeStream)
- {
- stream.Dispose();
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive.Tar
+{
+ internal class TarWritableArchiveEntry : TarArchiveEntry, IWritableArchiveEntry
+ {
+ private readonly string path;
+ private readonly long size;
+ private readonly DateTime? lastModified;
+ private readonly bool closeStream;
+ private readonly Stream stream;
+
+ internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType,
+ string path, long size, DateTime? lastModified, bool closeStream)
+ : base(archive, null, compressionType)
+ {
+ this.stream = stream;
+ this.path = path;
+ this.size = size;
+ this.lastModified = lastModified;
+ this.closeStream = closeStream;
+ }
+
+ public override long Crc
+ {
+ get { return 0; }
+ }
+
+ public override string Key
+ {
+ get { return path; }
+ }
+
+ public override long CompressedSize
+ {
+ get { return 0; }
+ }
+
+ public override long Size
+ {
+ get { return size; }
+ }
+
+ public override DateTime? LastModifiedTime
+ {
+ get { return lastModified; }
+ }
+
+ public override DateTime? CreatedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? LastAccessedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? ArchivedTime
+ {
+ get { return null; }
+ }
+
+ public override bool IsEncrypted
+ {
+ get { return false; }
+ }
+
+ public override bool IsDirectory
+ {
+ get { return false; }
+ }
+
+ public override bool IsSplit
+ {
+ get { return false; }
+ }
+
+ internal override IEnumerable Parts
+ {
+ get { throw new NotImplementedException(); }
+ }
+ Stream IWritableArchiveEntry.Stream
+ {
+ get
+ {
+ return stream;
+ }
+ }
+
+ public override Stream OpenEntryStream()
+ {
+ //ensure new stream is at the start, this could be reset
+ stream.Seek(0, SeekOrigin.Begin);
+ return new NonDisposingStream(stream);
+ }
+
+ internal override void Close()
+ {
+ if (closeStream)
+ {
+ stream.Dispose();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Zip/ZipArchive.cs b/src/SharpCompress/Archive/Zip/ZipArchive.cs
similarity index 96%
rename from SharpCompress/Archive/Zip/ZipArchive.cs
rename to src/SharpCompress/Archive/Zip/ZipArchive.cs
index 61a5e3f8..a9ae08f5 100644
--- a/SharpCompress/Archive/Zip/ZipArchive.cs
+++ b/src/SharpCompress/Archive/Zip/ZipArchive.cs
@@ -1,245 +1,245 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SharpCompress.Common;
-using SharpCompress.Common.Zip;
-using SharpCompress.Common.Zip.Headers;
-using SharpCompress.Compressor.Deflate;
-using SharpCompress.Reader;
-using SharpCompress.Reader.Zip;
-using SharpCompress.Writer.Zip;
-
-namespace SharpCompress.Archive.Zip
-{
- public class ZipArchive : AbstractWritableArchive
- {
- private readonly SeekableZipHeaderFactory headerFactory;
-
- ///
- /// Gets or sets the compression level applied to files added to the archive,
- /// if the compression method is set to deflate
- ///
- public CompressionLevel DeflateCompressionLevel { get; set; }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- public static ZipArchive Open(string filePath, string password = null)
- {
- return Open(filePath, Options.None, password);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- public static ZipArchive Open(FileInfo fileInfo, string password = null)
- {
- return Open(fileInfo, Options.None, password);
- }
-
- ///
- /// Constructor expects a filepath to an existing file.
- ///
- ///
- ///
- ///
- public static ZipArchive Open(string filePath, Options options, string password = null)
- {
- filePath.CheckNotNullOrEmpty("filePath");
- return Open(new FileInfo(filePath), options, password);
- }
-
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- ///
- public static ZipArchive Open(FileInfo fileInfo, Options options, string password = null)
- {
- fileInfo.CheckNotNull("fileInfo");
- return new ZipArchive(fileInfo, options, password);
- }
-#endif
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- public static ZipArchive Open(Stream stream, string password = null)
- {
- stream.CheckNotNull("stream");
- return Open(stream, Options.None, password);
- }
-
- ///
- /// Takes a seekable Stream as a source
- ///
- ///
- ///
- ///
- public static ZipArchive Open(Stream stream, Options options, string password = null)
- {
- stream.CheckNotNull("stream");
- return new ZipArchive(stream, options, password);
- }
-
-#if !PORTABLE && !NETFX_CORE
- public static bool IsZipFile(string filePath, string password = null)
- {
- return IsZipFile(new FileInfo(filePath), password);
- }
-
- public static bool IsZipFile(FileInfo fileInfo, string password = null)
- {
- if (!fileInfo.Exists)
- {
- return false;
- }
- using (Stream stream = fileInfo.OpenRead())
- {
- return IsZipFile(stream, password);
- }
- }
-#endif
-
- public static bool IsZipFile(Stream stream, string password = null)
- {
- StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password);
- try
- {
- ZipHeader header =
- headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
- if (header == null)
- {
- return false;
- }
- return Enum.IsDefined(typeof (ZipHeaderType), header.ZipHeaderType);
- }
- catch (CryptographicException)
- {
- return true;
- }
- catch
- {
- return false;
- }
- }
-
-#if !PORTABLE && !NETFX_CORE
- ///
- /// Constructor with a FileInfo object to an existing file.
- ///
- ///
- ///
- ///
- internal ZipArchive(FileInfo fileInfo, Options options, string password = null)
- : base(ArchiveType.Zip, fileInfo, options)
- {
- headerFactory = new SeekableZipHeaderFactory(password);
- }
-
- protected override IEnumerable LoadVolumes(FileInfo file, Options options)
- {
- if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
- {
- options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
- }
- return new ZipVolume(file.OpenRead(), options).AsEnumerable();
- }
-#endif
-
- internal ZipArchive()
- : base(ArchiveType.Zip)
- {
- }
-
- ///
- /// Takes multiple seekable Streams for a multi-part archive
- ///
- ///
- ///
- ///
- internal ZipArchive(Stream stream, Options options, string password = null)
- : base(ArchiveType.Zip, stream, options)
- {
- headerFactory = new SeekableZipHeaderFactory(password);
- }
-
- protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
- {
- return new ZipVolume(streams.First(), options).AsEnumerable();
- }
-
- protected override IEnumerable LoadEntries(IEnumerable volumes)
- {
- var volume = volumes.Single();
- Stream stream = volume.Stream;
- foreach (ZipHeader h in headerFactory.ReadSeekableHeader(stream))
- {
- if (h != null)
- {
- switch (h.ZipHeaderType)
- {
- case ZipHeaderType.DirectoryEntry:
- {
- yield return new ZipArchiveEntry(this,
- new SeekableZipFilePart(headerFactory,
- h as DirectoryEntryHeader,
- stream));
- }
- break;
- case ZipHeaderType.DirectoryEnd:
- {
- byte[] bytes = (h as DirectoryEndHeader).Comment;
- volume.Comment = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length);
- yield break;
- }
- }
- }
- }
- }
-
- protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
- IEnumerable oldEntries,
- IEnumerable newEntries)
- {
- using (var writer = new ZipWriter(stream, compressionInfo, string.Empty))
- {
- foreach (var entry in oldEntries.Concat(newEntries)
- .Where(x => !x.IsDirectory))
- {
- using (var entryStream = entry.OpenEntryStream())
- {
- writer.Write(entry.Key, entryStream, entry.LastModifiedTime, string.Empty);
- }
- }
- }
- }
-
- protected override ZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
- bool closeStream)
- {
- return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
- }
-
- public static ZipArchive Create()
- {
- return new ZipArchive();
- }
-
- protected override IReader CreateReaderForSolidExtraction()
- {
- var stream = Volumes.Single().Stream;
- stream.Position = 0;
- return ZipReader.Open(stream);
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SharpCompress.Common;
+using SharpCompress.Common.Zip;
+using SharpCompress.Common.Zip.Headers;
+using SharpCompress.Compressor.Deflate;
+using SharpCompress.Reader;
+using SharpCompress.Reader.Zip;
+using SharpCompress.Writer.Zip;
+
+namespace SharpCompress.Archive.Zip
+{
+ public class ZipArchive : AbstractWritableArchive
+ {
+ private readonly SeekableZipHeaderFactory headerFactory;
+
+ ///
+ /// Gets or sets the compression level applied to files added to the archive,
+ /// if the compression method is set to deflate
+ ///
+ public CompressionLevel DeflateCompressionLevel { get; set; }
+
+#if !NO_FILE
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ public static ZipArchive Open(string filePath, string password = null)
+ {
+ return Open(filePath, Options.None, password);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ public static ZipArchive Open(FileInfo fileInfo, string password = null)
+ {
+ return Open(fileInfo, Options.None, password);
+ }
+
+ ///
+ /// Constructor expects a filepath to an existing file.
+ ///
+ ///
+ ///
+ ///
+ public static ZipArchive Open(string filePath, Options options, string password = null)
+ {
+ filePath.CheckNotNullOrEmpty("filePath");
+ return Open(new FileInfo(filePath), options, password);
+ }
+
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ ///
+ public static ZipArchive Open(FileInfo fileInfo, Options options, string password = null)
+ {
+ fileInfo.CheckNotNull("fileInfo");
+ return new ZipArchive(fileInfo, options, password);
+ }
+#endif
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ public static ZipArchive Open(Stream stream, string password = null)
+ {
+ stream.CheckNotNull("stream");
+ return Open(stream, Options.None, password);
+ }
+
+ ///
+ /// Takes a seekable Stream as a source
+ ///
+ ///
+ ///
+ ///
+ public static ZipArchive Open(Stream stream, Options options, string password = null)
+ {
+ stream.CheckNotNull("stream");
+ return new ZipArchive(stream, options, password);
+ }
+
+#if !NO_FILE
+ public static bool IsZipFile(string filePath, string password = null)
+ {
+ return IsZipFile(new FileInfo(filePath), password);
+ }
+
+ public static bool IsZipFile(FileInfo fileInfo, string password = null)
+ {
+ if (!fileInfo.Exists)
+ {
+ return false;
+ }
+ using (Stream stream = fileInfo.OpenRead())
+ {
+ return IsZipFile(stream, password);
+ }
+ }
+#endif
+
+ public static bool IsZipFile(Stream stream, string password = null)
+ {
+ StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password);
+ try
+ {
+ ZipHeader header =
+ headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
+ if (header == null)
+ {
+ return false;
+ }
+ return Enum.IsDefined(typeof (ZipHeaderType), header.ZipHeaderType);
+ }
+ catch (CryptographicException)
+ {
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+#if !NO_FILE
+ ///
+ /// Constructor with a FileInfo object to an existing file.
+ ///
+ ///
+ ///
+ ///
+ internal ZipArchive(FileInfo fileInfo, Options options, string password = null)
+ : base(ArchiveType.Zip, fileInfo, options)
+ {
+ headerFactory = new SeekableZipHeaderFactory(password);
+ }
+
+ protected override IEnumerable LoadVolumes(FileInfo file, Options options)
+ {
+ if (FlagUtility.HasFlag(options, Options.KeepStreamsOpen))
+ {
+ options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
+ }
+ return new ZipVolume(file.OpenRead(), options).AsEnumerable();
+ }
+#endif
+
+ internal ZipArchive()
+ : base(ArchiveType.Zip)
+ {
+ }
+
+ ///
+ /// Takes multiple seekable Streams for a multi-part archive
+ ///
+ ///
+ ///
+ ///
+ internal ZipArchive(Stream stream, Options options, string password = null)
+ : base(ArchiveType.Zip, stream, options)
+ {
+ headerFactory = new SeekableZipHeaderFactory(password);
+ }
+
+ protected override IEnumerable LoadVolumes(IEnumerable streams, Options options)
+ {
+ return new ZipVolume(streams.First(), options).AsEnumerable();
+ }
+
+ protected override IEnumerable LoadEntries(IEnumerable volumes)
+ {
+ var volume = volumes.Single();
+ Stream stream = volume.Stream;
+ foreach (ZipHeader h in headerFactory.ReadSeekableHeader(stream))
+ {
+ if (h != null)
+ {
+ switch (h.ZipHeaderType)
+ {
+ case ZipHeaderType.DirectoryEntry:
+ {
+ yield return new ZipArchiveEntry(this,
+ new SeekableZipFilePart(headerFactory,
+ h as DirectoryEntryHeader,
+ stream));
+ }
+ break;
+ case ZipHeaderType.DirectoryEnd:
+ {
+ byte[] bytes = (h as DirectoryEndHeader).Comment;
+ volume.Comment = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length);
+ yield break;
+ }
+ }
+ }
+ }
+ }
+
+ protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
+ IEnumerable oldEntries,
+ IEnumerable newEntries)
+ {
+ using (var writer = new ZipWriter(stream, compressionInfo, string.Empty))
+ {
+ foreach (var entry in oldEntries.Concat(newEntries)
+ .Where(x => !x.IsDirectory))
+ {
+ using (var entryStream = entry.OpenEntryStream())
+ {
+ writer.Write(entry.Key, entryStream, entry.LastModifiedTime, string.Empty);
+ }
+ }
+ }
+ }
+
+ protected override ZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
+ bool closeStream)
+ {
+ return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
+ }
+
+ public static ZipArchive Create()
+ {
+ return new ZipArchive();
+ }
+
+ protected override IReader CreateReaderForSolidExtraction()
+ {
+ var stream = Volumes.Single().Stream;
+ stream.Position = 0;
+ return ZipReader.Open(stream);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Zip/ZipArchiveEntry.cs b/src/SharpCompress/Archive/Zip/ZipArchiveEntry.cs
similarity index 95%
rename from SharpCompress/Archive/Zip/ZipArchiveEntry.cs
rename to src/SharpCompress/Archive/Zip/ZipArchiveEntry.cs
index 70d4b229..607f7a58 100644
--- a/SharpCompress/Archive/Zip/ZipArchiveEntry.cs
+++ b/src/SharpCompress/Archive/Zip/ZipArchiveEntry.cs
@@ -1,36 +1,36 @@
-using System.IO;
-using System.Linq;
-using SharpCompress.Common.Zip;
-
-namespace SharpCompress.Archive.Zip
-{
- public class ZipArchiveEntry : ZipEntry, IArchiveEntry
- {
- internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart part)
- : base(part)
- {
- Archive = archive;
- }
-
- public virtual Stream OpenEntryStream()
- {
- return Parts.Single().GetCompressedStream();
- }
-
- #region IArchiveEntry Members
-
- public IArchive Archive { get; private set; }
-
- public bool IsComplete
- {
- get { return true; }
- }
-
- #endregion
-
- public string Comment
- {
- get { return (Parts.Single() as SeekableZipFilePart).Comment; }
- }
- }
+using System.IO;
+using System.Linq;
+using SharpCompress.Common.Zip;
+
+namespace SharpCompress.Archive.Zip
+{
+ public class ZipArchiveEntry : ZipEntry, IArchiveEntry
+ {
+ internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart part)
+ : base(part)
+ {
+ Archive = archive;
+ }
+
+ public virtual Stream OpenEntryStream()
+ {
+ return Parts.Single().GetCompressedStream();
+ }
+
+ #region IArchiveEntry Members
+
+ public IArchive Archive { get; private set; }
+
+ public bool IsComplete
+ {
+ get { return true; }
+ }
+
+ #endregion
+
+ public string Comment
+ {
+ get { return (Parts.Single() as SeekableZipFilePart).Comment; }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs b/src/SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs
similarity index 95%
rename from SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs
rename to src/SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs
index ce99ce40..f1946e7a 100644
--- a/SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archive/Zip/ZipWritableArchiveEntry.cs
@@ -1,113 +1,113 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using SharpCompress.Common;
-using SharpCompress.IO;
-
-namespace SharpCompress.Archive.Zip
-{
- internal class ZipWritableArchiveEntry : ZipArchiveEntry, IWritableArchiveEntry
- {
- private readonly string path;
- private readonly long size;
- private readonly DateTime? lastModified;
- private readonly bool closeStream;
- private readonly Stream stream;
- private bool isDisposed;
-
- internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
- DateTime? lastModified, bool closeStream)
- : base(archive, null)
- {
- this.stream = stream;
- this.path = path;
- this.size = size;
- this.lastModified = lastModified;
- this.closeStream = closeStream;
- }
-
- public override long Crc
- {
- get { return 0; }
- }
-
- public override string Key
- {
- get { return path; }
- }
-
- public override long CompressedSize
- {
- get { return 0; }
- }
-
- public override long Size
- {
- get { return size; }
- }
-
- public override DateTime? LastModifiedTime
- {
- get { return lastModified; }
- }
-
- public override DateTime? CreatedTime
- {
- get { return null; }
- }
-
- public override DateTime? LastAccessedTime
- {
- get { return null; }
- }
-
- public override DateTime? ArchivedTime
- {
- get { return null; }
- }
-
- public override bool IsEncrypted
- {
- get { return false; }
- }
-
- public override bool IsDirectory
- {
- get { return false; }
- }
-
- public override bool IsSplit
- {
- get { return false; }
- }
-
- internal override IEnumerable Parts
- {
- get { throw new NotImplementedException(); }
- }
-
- Stream IWritableArchiveEntry.Stream
- {
- get
- {
- return stream;
- }
- }
-
- public override Stream OpenEntryStream()
- {
- //ensure new stream is at the start, this could be reset
- stream.Seek(0, SeekOrigin.Begin);
- return new NonDisposingStream(stream);
- }
-
- internal override void Close()
- {
- if (closeStream && !isDisposed)
- {
- stream.Dispose();
- isDisposed = true;
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Common;
+using SharpCompress.IO;
+
+namespace SharpCompress.Archive.Zip
+{
+ internal class ZipWritableArchiveEntry : ZipArchiveEntry, IWritableArchiveEntry
+ {
+ private readonly string path;
+ private readonly long size;
+ private readonly DateTime? lastModified;
+ private readonly bool closeStream;
+ private readonly Stream stream;
+ private bool isDisposed;
+
+ internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
+ DateTime? lastModified, bool closeStream)
+ : base(archive, null)
+ {
+ this.stream = stream;
+ this.path = path;
+ this.size = size;
+ this.lastModified = lastModified;
+ this.closeStream = closeStream;
+ }
+
+ public override long Crc
+ {
+ get { return 0; }
+ }
+
+ public override string Key
+ {
+ get { return path; }
+ }
+
+ public override long CompressedSize
+ {
+ get { return 0; }
+ }
+
+ public override long Size
+ {
+ get { return size; }
+ }
+
+ public override DateTime? LastModifiedTime
+ {
+ get { return lastModified; }
+ }
+
+ public override DateTime? CreatedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? LastAccessedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? ArchivedTime
+ {
+ get { return null; }
+ }
+
+ public override bool IsEncrypted
+ {
+ get { return false; }
+ }
+
+ public override bool IsDirectory
+ {
+ get { return false; }
+ }
+
+ public override bool IsSplit
+ {
+ get { return false; }
+ }
+
+ internal override IEnumerable Parts
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ Stream IWritableArchiveEntry.Stream
+ {
+ get
+ {
+ return stream;
+ }
+ }
+
+ public override Stream OpenEntryStream()
+ {
+ //ensure new stream is at the start, this could be reset
+ stream.Seek(0, SeekOrigin.Begin);
+ return new NonDisposingStream(stream);
+ }
+
+ internal override void Close()
+ {
+ if (closeStream && !isDisposed)
+ {
+ stream.Dispose();
+ isDisposed = true;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/AssemblyInfo.cs b/src/SharpCompress/AssemblyInfo.cs
similarity index 65%
rename from SharpCompress/AssemblyInfo.cs
rename to src/SharpCompress/AssemblyInfo.cs
index ce29fd3c..8978eeba 100644
--- a/SharpCompress/AssemblyInfo.cs
+++ b/src/SharpCompress/AssemblyInfo.cs
@@ -1,20 +1,13 @@
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-
-#if PORTABLE
-[assembly: AssemblyTitle("SharpCompress.Portable")]
-[assembly: AssemblyProduct("SharpCompress.Portable")]
-#else
-
-[assembly: AssemblyTitle("SharpCompress")]
-[assembly: AssemblyProduct("SharpCompress")]
-#endif
-
-#if UNSIGNED
-[assembly: InternalsVisibleTo("SharpCompress.Test")]
-[assembly: InternalsVisibleTo("SharpCompress.Test.Portable")]
-#endif
-
-[assembly: CLSCompliant(true)]
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+
+[assembly: AssemblyTitle("SharpCompress")]
+[assembly: AssemblyProduct("SharpCompress")]
+
+
+[assembly: InternalsVisibleTo("SharpCompress.Test")]
+[assembly: InternalsVisibleTo("SharpCompress.Test.Portable")]
+
+[assembly: CLSCompliant(true)]
diff --git a/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs
similarity index 96%
rename from SharpCompress/Common/ArchiveEncoding.cs
rename to src/SharpCompress/Common/ArchiveEncoding.cs
index 98cb6f7d..c973c7cb 100644
--- a/SharpCompress/Common/ArchiveEncoding.cs
+++ b/src/SharpCompress/Common/ArchiveEncoding.cs
@@ -1,23 +1,23 @@
-using System.Text;
-
-namespace SharpCompress.Common
-{
- public static class ArchiveEncoding
- {
- ///
- /// Default encoding to use when archive format doesn't specify one.
- ///
- public static Encoding Default { get; set; }
-
- ///
- /// Encoding used by encryption schemes which don't comply with RFC 2898.
- ///
- public static Encoding Password { get; set; }
-
- static ArchiveEncoding()
- {
- Default = Encoding.UTF8;
- Password = Encoding.UTF8;
- }
- }
+using System.Text;
+
+namespace SharpCompress.Common
+{
+ public static class ArchiveEncoding
+ {
+ ///
+ /// Default encoding to use when archive format doesn't specify one.
+ ///
+ public static Encoding Default { get; set; }
+
+ ///
+ /// Encoding used by encryption schemes which don't comply with RFC 2898.
+ ///
+ public static Encoding Password { get; set; }
+
+ static ArchiveEncoding()
+ {
+ Default = Encoding.UTF8;
+ Password = Encoding.UTF8;
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/ArchiveException.cs b/src/SharpCompress/Common/ArchiveException.cs
similarity index 94%
rename from SharpCompress/Common/ArchiveException.cs
rename to src/SharpCompress/Common/ArchiveException.cs
index 3a969784..18207c64 100644
--- a/SharpCompress/Common/ArchiveException.cs
+++ b/src/SharpCompress/Common/ArchiveException.cs
@@ -1,12 +1,12 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class ArchiveException : Exception
- {
- public ArchiveException(string message)
- : base(message)
- {
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class ArchiveException : Exception
+ {
+ public ArchiveException(string message)
+ : base(message)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/ArchiveExtractionEventArgs.cs b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs
similarity index 95%
rename from SharpCompress/Common/ArchiveExtractionEventArgs.cs
rename to src/SharpCompress/Common/ArchiveExtractionEventArgs.cs
index 1a4cba25..7295fdf4 100644
--- a/SharpCompress/Common/ArchiveExtractionEventArgs.cs
+++ b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs
@@ -1,14 +1,14 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class ArchiveExtractionEventArgs : EventArgs
- {
- internal ArchiveExtractionEventArgs(T entry)
- {
- Item = entry;
- }
-
- public T Item { get; private set; }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class ArchiveExtractionEventArgs : EventArgs
+ {
+ internal ArchiveExtractionEventArgs(T entry)
+ {
+ Item = entry;
+ }
+
+ public T Item { get; private set; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/ArchiveType.cs b/src/SharpCompress/Common/ArchiveType.cs
similarity index 93%
rename from SharpCompress/Common/ArchiveType.cs
rename to src/SharpCompress/Common/ArchiveType.cs
index 2b405356..ca905f42 100644
--- a/SharpCompress/Common/ArchiveType.cs
+++ b/src/SharpCompress/Common/ArchiveType.cs
@@ -1,11 +1,11 @@
-namespace SharpCompress.Common
-{
- public enum ArchiveType
- {
- Rar,
- Zip,
- Tar,
- SevenZip,
- GZip,
- }
+namespace SharpCompress.Common
+{
+ public enum ArchiveType
+ {
+ Rar,
+ Zip,
+ Tar,
+ SevenZip,
+ GZip,
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/CompressedBytesReadEventArgs.cs b/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs
similarity index 96%
rename from SharpCompress/Common/CompressedBytesReadEventArgs.cs
rename to src/SharpCompress/Common/CompressedBytesReadEventArgs.cs
index 7c8ed598..fdae9c4d 100644
--- a/SharpCompress/Common/CompressedBytesReadEventArgs.cs
+++ b/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs
@@ -1,17 +1,17 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class CompressedBytesReadEventArgs : EventArgs
- {
- ///
- /// Compressed bytes read for the current entry
- ///
- public long CompressedBytesRead { get; internal set; }
-
- ///
- /// Current file part read for Multipart files (e.g. Rar)
- ///
- public long CurrentFilePartCompressedBytesRead { get; internal set; }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class CompressedBytesReadEventArgs : EventArgs
+ {
+ ///
+ /// Compressed bytes read for the current entry
+ ///
+ public long CompressedBytesRead { get; internal set; }
+
+ ///
+ /// Current file part read for Multipart files (e.g. Rar)
+ ///
+ public long CurrentFilePartCompressedBytesRead { get; internal set; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/CompressionInfo.cs b/src/SharpCompress/Common/CompressionInfo.cs
similarity index 96%
rename from SharpCompress/Common/CompressionInfo.cs
rename to src/SharpCompress/Common/CompressionInfo.cs
index f62ea405..2ad5703b 100644
--- a/SharpCompress/Common/CompressionInfo.cs
+++ b/src/SharpCompress/Common/CompressionInfo.cs
@@ -1,30 +1,30 @@
-using SharpCompress.Compressor.Deflate;
-
-namespace SharpCompress.Common
-{
- ///
- /// Detailed compression properties when saving.
- ///
- public class CompressionInfo
- {
- public CompressionInfo()
- {
- DeflateCompressionLevel = CompressionLevel.Default;
- }
-
- ///
- /// The algorthm to use. Must be valid for the format type.
- ///
- public CompressionType Type { get; set; }
-
- ///
- /// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
- ///
- public CompressionLevel DeflateCompressionLevel { get; set; }
-
- public static implicit operator CompressionInfo(CompressionType compressionType)
- {
- return new CompressionInfo() {Type = compressionType};
- }
- }
+using SharpCompress.Compressor.Deflate;
+
+namespace SharpCompress.Common
+{
+ ///
+ /// Detailed compression properties when saving.
+ ///
+ public class CompressionInfo
+ {
+ public CompressionInfo()
+ {
+ DeflateCompressionLevel = CompressionLevel.Default;
+ }
+
+ ///
+ /// The algorthm to use. Must be valid for the format type.
+ ///
+ public CompressionType Type { get; set; }
+
+ ///
+ /// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
+ ///
+ public CompressionLevel DeflateCompressionLevel { get; set; }
+
+ public static implicit operator CompressionInfo(CompressionType compressionType)
+ {
+ return new CompressionInfo() {Type = compressionType};
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/CompressionType.cs b/src/SharpCompress/Common/CompressionType.cs
similarity index 93%
rename from SharpCompress/Common/CompressionType.cs
rename to src/SharpCompress/Common/CompressionType.cs
index d51e6545..20d59a2b 100644
--- a/SharpCompress/Common/CompressionType.cs
+++ b/src/SharpCompress/Common/CompressionType.cs
@@ -1,16 +1,16 @@
-namespace SharpCompress.Common
-{
- public enum CompressionType
- {
- None,
- GZip,
- BZip2,
- PPMd,
- Deflate,
- Rar,
- LZMA,
- BCJ,
- BCJ2,
- Unknown,
- }
+namespace SharpCompress.Common
+{
+ public enum CompressionType
+ {
+ None,
+ GZip,
+ BZip2,
+ PPMd,
+ Deflate,
+ Rar,
+ LZMA,
+ BCJ,
+ BCJ2,
+ Unknown,
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/CryptographicException.cs b/src/SharpCompress/Common/CryptographicException.cs
similarity index 95%
rename from SharpCompress/Common/CryptographicException.cs
rename to src/SharpCompress/Common/CryptographicException.cs
index 4e17f303..450cd237 100644
--- a/SharpCompress/Common/CryptographicException.cs
+++ b/src/SharpCompress/Common/CryptographicException.cs
@@ -1,12 +1,12 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class CryptographicException : Exception
- {
- public CryptographicException(string message)
- : base(message)
- {
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class CryptographicException : Exception
+ {
+ public CryptographicException(string message)
+ : base(message)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/Entry.cs b/src/SharpCompress/Common/Entry.cs
similarity index 96%
rename from SharpCompress/Common/Entry.cs
rename to src/SharpCompress/Common/Entry.cs
index 42d90faf..3f1aac1b 100644
--- a/SharpCompress/Common/Entry.cs
+++ b/src/SharpCompress/Common/Entry.cs
@@ -1,85 +1,85 @@
-using System;
-using System.Collections.Generic;
-
-namespace SharpCompress.Common
-{
- public abstract class Entry : IEntry
- {
- ///
- /// The File's 32 bit CRC Hash
- ///
- public abstract long Crc { get; }
-
- ///
- /// The string key of the file internal to the Archive.
- ///
- public abstract string Key { get; }
-
- ///
- /// The compressed file size
- ///
- public abstract long CompressedSize { get; }
-
- ///
- /// The compression type
- ///
- public abstract CompressionType CompressionType { get; }
-
- ///
- /// The uncompressed file size
- ///
- public abstract long Size { get; }
-
- ///
- /// The entry last modified time in the archive, if recorded
- ///
- public abstract DateTime? LastModifiedTime { get; }
-
- ///
- /// The entry create time in the archive, if recorded
- ///
- public abstract DateTime? CreatedTime { get; }
-
- ///
- /// The entry last accessed time in the archive, if recorded
- ///
- public abstract DateTime? LastAccessedTime { get; }
-
- ///
- /// The entry time when archived, if recorded
- ///
- public abstract DateTime? ArchivedTime { get; }
-
- ///
- /// Entry is password protected and encrypted and cannot be extracted.
- ///
- public abstract bool IsEncrypted { get; }
-
- ///
- /// Entry is password protected and encrypted and cannot be extracted.
- ///
- public abstract bool IsDirectory { get; }
-
- ///
- /// Entry is split among multiple volumes
- ///
- public abstract bool IsSplit { get; }
-
- internal abstract IEnumerable Parts { get; }
- internal bool IsSolid { get; set; }
-
- internal virtual void Close()
- {
-
- }
-
- ///
- /// Entry file attribute.
- ///
- public virtual int? Attrib
- {
- get { throw new NotImplementedException(); }
- }
-
- }
+using System;
+using System.Collections.Generic;
+
+namespace SharpCompress.Common
+{
+ public abstract class Entry : IEntry
+ {
+ ///
+ /// The File's 32 bit CRC Hash
+ ///
+ public abstract long Crc { get; }
+
+ ///
+ /// The string key of the file internal to the Archive.
+ ///
+ public abstract string Key { get; }
+
+ ///
+ /// The compressed file size
+ ///
+ public abstract long CompressedSize { get; }
+
+ ///
+ /// The compression type
+ ///
+ public abstract CompressionType CompressionType { get; }
+
+ ///
+ /// The uncompressed file size
+ ///
+ public abstract long Size { get; }
+
+ ///
+ /// The entry last modified time in the archive, if recorded
+ ///
+ public abstract DateTime? LastModifiedTime { get; }
+
+ ///
+ /// The entry create time in the archive, if recorded
+ ///
+ public abstract DateTime? CreatedTime { get; }
+
+ ///
+ /// The entry last accessed time in the archive, if recorded
+ ///
+ public abstract DateTime? LastAccessedTime { get; }
+
+ ///
+ /// The entry time when archived, if recorded
+ ///
+ public abstract DateTime? ArchivedTime { get; }
+
+ ///
+ /// Entry is password protected and encrypted and cannot be extracted.
+ ///
+ public abstract bool IsEncrypted { get; }
+
+ ///
+ /// Entry is password protected and encrypted and cannot be extracted.
+ ///
+ public abstract bool IsDirectory { get; }
+
+ ///
+ /// Entry is split among multiple volumes
+ ///
+ public abstract bool IsSplit { get; }
+
+ internal abstract IEnumerable Parts { get; }
+ internal bool IsSolid { get; set; }
+
+ internal virtual void Close()
+ {
+
+ }
+
+ ///
+ /// Entry file attribute.
+ ///
+ public virtual int? Attrib
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/EntryStream.cs b/src/SharpCompress/Common/EntryStream.cs
similarity index 96%
rename from SharpCompress/Common/EntryStream.cs
rename to src/SharpCompress/Common/EntryStream.cs
index 86e50978..f3fd99ac 100644
--- a/SharpCompress/Common/EntryStream.cs
+++ b/src/SharpCompress/Common/EntryStream.cs
@@ -1,103 +1,103 @@
-using System;
-using System.IO;
-using SharpCompress.Reader;
-
-namespace SharpCompress.Common
-{
- public class EntryStream : Stream
- {
- public IReader Reader { get; private set; }
- private Stream stream;
- private bool completed;
- private bool isDisposed;
-
- internal EntryStream(IReader reader, Stream stream)
- {
- this.Reader = reader;
- this.stream = stream;
- }
-
- ///
- /// When reading a stream from OpenEntryStream, the stream must be completed so use this to finish reading the entire entry.
- ///
- public void SkipEntry()
- {
- var buffer = new byte[4096];
- while (Read(buffer, 0, buffer.Length) > 0)
- {
- }
- completed = true;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (!(completed || Reader.Cancelled))
- {
- SkipEntry();
- }
- if (isDisposed)
- {
- return;
- }
- isDisposed = true;
- base.Dispose(disposing);
- stream.Dispose();
- }
-
- public override bool CanRead
- {
- get { return true; }
- }
-
- public override bool CanSeek
- {
- get { return false; }
- }
-
- public override bool CanWrite
- {
- get { return false; }
- }
-
- public override void Flush()
- {
- throw new NotSupportedException();
- }
-
- public override long Length
- {
- get { throw new NotSupportedException(); }
- }
-
- public override long Position
- {
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- int read = stream.Read(buffer, offset, count);
- if (read <= 0)
- {
- completed = true;
- }
- return read;
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotSupportedException();
- }
-
- public override void SetLength(long value)
- {
- throw new NotSupportedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotSupportedException();
- }
- }
+using System;
+using System.IO;
+using SharpCompress.Reader;
+
+namespace SharpCompress.Common
+{
+ public class EntryStream : Stream
+ {
+ public IReader Reader { get; private set; }
+ private Stream stream;
+ private bool completed;
+ private bool isDisposed;
+
+ internal EntryStream(IReader reader, Stream stream)
+ {
+ this.Reader = reader;
+ this.stream = stream;
+ }
+
+ ///
+ /// When reading a stream from OpenEntryStream, the stream must be completed so use this to finish reading the entire entry.
+ ///
+ public void SkipEntry()
+ {
+ var buffer = new byte[4096];
+ while (Read(buffer, 0, buffer.Length) > 0)
+ {
+ }
+ completed = true;
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (!(completed || Reader.Cancelled))
+ {
+ SkipEntry();
+ }
+ if (isDisposed)
+ {
+ return;
+ }
+ isDisposed = true;
+ base.Dispose(disposing);
+ stream.Dispose();
+ }
+
+ public override bool CanRead
+ {
+ get { return true; }
+ }
+
+ public override bool CanSeek
+ {
+ get { return false; }
+ }
+
+ public override bool CanWrite
+ {
+ get { return false; }
+ }
+
+ public override void Flush()
+ {
+ throw new NotSupportedException();
+ }
+
+ public override long Length
+ {
+ get { throw new NotSupportedException(); }
+ }
+
+ public override long Position
+ {
+ get { throw new NotSupportedException(); }
+ set { throw new NotSupportedException(); }
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ int read = stream.Read(buffer, offset, count);
+ if (read <= 0)
+ {
+ completed = true;
+ }
+ return read;
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotSupportedException();
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/ExtractOptions.cs b/src/SharpCompress/Common/ExtractOptions.cs
similarity index 95%
rename from SharpCompress/Common/ExtractOptions.cs
rename to src/SharpCompress/Common/ExtractOptions.cs
index 0aff140e..85c92668 100644
--- a/SharpCompress/Common/ExtractOptions.cs
+++ b/src/SharpCompress/Common/ExtractOptions.cs
@@ -1,30 +1,30 @@
-using System;
-
-namespace SharpCompress.Common
-{
- [Flags]
- public enum ExtractOptions
- {
- None = 0,
-
- ///
- /// overwrite target if it exists
- ///
- Overwrite = 1 << 0,
-
- ///
- /// extract with internal directory structure
- ///
- ExtractFullPath = 1 << 1,
-
- ///
- /// preserve file time
- ///
- PreserveFileTime = 1 << 2,
-
- ///
- /// preserve windows file attributes
- ///
- PreserveAttributes = 1 << 3,
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ [Flags]
+ public enum ExtractOptions
+ {
+ None = 0,
+
+ ///
+ /// overwrite target if it exists
+ ///
+ Overwrite = 1 << 0,
+
+ ///
+ /// extract with internal directory structure
+ ///
+ ExtractFullPath = 1 << 1,
+
+ ///
+ /// preserve file time
+ ///
+ PreserveFileTime = 1 << 2,
+
+ ///
+ /// preserve windows file attributes
+ ///
+ PreserveAttributes = 1 << 3,
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/ExtractionException.cs b/src/SharpCompress/Common/ExtractionException.cs
similarity index 95%
rename from SharpCompress/Common/ExtractionException.cs
rename to src/SharpCompress/Common/ExtractionException.cs
index 15224d4d..be5e688c 100644
--- a/SharpCompress/Common/ExtractionException.cs
+++ b/src/SharpCompress/Common/ExtractionException.cs
@@ -1,17 +1,17 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class ExtractionException : Exception
- {
- public ExtractionException(string message)
- : base(message)
- {
- }
-
- public ExtractionException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class ExtractionException : Exception
+ {
+ public ExtractionException(string message)
+ : base(message)
+ {
+ }
+
+ public ExtractionException(string message, Exception inner)
+ : base(message, inner)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/FilePart.cs b/src/SharpCompress/Common/FilePart.cs
similarity index 95%
rename from SharpCompress/Common/FilePart.cs
rename to src/SharpCompress/Common/FilePart.cs
index c9bbd636..b57ef613 100644
--- a/SharpCompress/Common/FilePart.cs
+++ b/src/SharpCompress/Common/FilePart.cs
@@ -1,12 +1,12 @@
-using System.IO;
-
-namespace SharpCompress.Common
-{
- public abstract class FilePart
- {
- internal abstract string FilePartName { get; }
-
- internal abstract Stream GetCompressedStream();
- internal abstract Stream GetRawStream();
- }
+using System.IO;
+
+namespace SharpCompress.Common
+{
+ public abstract class FilePart
+ {
+ internal abstract string FilePartName { get; }
+
+ internal abstract Stream GetCompressedStream();
+ internal abstract Stream GetRawStream();
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs b/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs
similarity index 96%
rename from SharpCompress/Common/FilePartExtractionBeginEventArgs.cs
rename to src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs
index b5742b6c..913f2093 100644
--- a/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs
+++ b/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs
@@ -1,22 +1,22 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class FilePartExtractionBeginEventArgs : EventArgs
- {
- ///
- /// File name for the part for the current entry
- ///
- public string Name { get; internal set; }
-
- ///
- /// Uncompressed size of the current entry in the part
- ///
- public long Size { get; internal set; }
-
- ///
- /// Compressed size of the current entry in the part
- ///
- public long CompressedSize { get; internal set; }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class FilePartExtractionBeginEventArgs : EventArgs
+ {
+ ///
+ /// File name for the part for the current entry
+ ///
+ public string Name { get; internal set; }
+
+ ///
+ /// Uncompressed size of the current entry in the part
+ ///
+ public long Size { get; internal set; }
+
+ ///
+ /// Compressed size of the current entry in the part
+ ///
+ public long CompressedSize { get; internal set; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/FlagUtility.cs b/src/SharpCompress/Common/FlagUtility.cs
similarity index 82%
rename from SharpCompress/Common/FlagUtility.cs
rename to src/SharpCompress/Common/FlagUtility.cs
index 545dc1d1..b6fc8664 100644
--- a/SharpCompress/Common/FlagUtility.cs
+++ b/src/SharpCompress/Common/FlagUtility.cs
@@ -1,130 +1,109 @@
-using System;
-
-namespace SharpCompress.Common
-{
- internal static class FlagUtility
- {
- ///
- /// Returns true if the flag is set on the specified bit field.
- /// Currently only works with 32-bit bitfields.
- ///
- /// Enumeration with Flags attribute
- /// Flagged variable
- /// Flag to test
- ///
- public static bool HasFlag(long bitField, T flag)
- where T : struct
- {
- return HasFlag(bitField, flag);
- }
-
- ///
- /// Returns true if the flag is set on the specified bit field.
- /// Currently only works with 32-bit bitfields.
- ///
- /// Enumeration with Flags attribute
- /// Flagged variable
- /// Flag to test
- ///
- public static bool HasFlag(ulong bitField, T flag)
- where T : struct
- {
- return HasFlag(bitField, flag);
- }
-
- ///
- /// Returns true if the flag is set on the specified bit field.
- /// Currently only works with 32-bit bitfields.
- ///
- /// Flagged variable
- /// Flag to test
- ///
- public static bool HasFlag(ulong bitField, ulong flag)
- {
- return ((bitField & flag) == flag);
- }
-
- public static bool HasFlag(short bitField, short flag)
- {
- return ((bitField & flag) == flag);
- }
-
-#if PORTABLE
- ///
- /// Generically checks enums in a Windows Phone 7 enivronment
- ///
- ///
- ///
- ///
- public static bool HasFlag(this Enum enumVal, Enum flag)
- {
- if (enumVal.GetHashCode() > 0) //GetHashCode returns the enum value. But it's something very crazy if not set beforehand
- {
- ulong num = Convert.ToUInt64(flag.GetHashCode());
- return ((Convert.ToUInt64(enumVal.GetHashCode()) & num) == num);
- }
- else
- {
- return false;
- }
- }
-#endif
-
- ///
- /// Returns true if the flag is set on the specified bit field.
- /// Currently only works with 32-bit bitfields.
- ///
- /// Enumeration with Flags attribute
- /// Flagged variable
- /// Flag to test
- ///
- public static bool HasFlag(T bitField, T flag)
- where T : struct
- {
- return HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag));
- }
-
- ///
- /// Returns true if the flag is set on the specified bit field.
- /// Currently only works with 32-bit bitfields.
- ///
- /// Flagged variable
- /// Flag to test
- ///
- public static bool HasFlag(long bitField, long flag)
- {
- return ((bitField & flag) == flag);
- }
-
-
- ///
- /// Sets a bit-field to either on or off for the specified flag.
- ///
- /// Flagged variable
- /// Flag to change
- /// bool
- /// The flagged variable with the flag changed
- public static long SetFlag(long bitField, long flag, bool @on)
- {
- if (@on)
- {
- return bitField | flag;
- }
- return bitField & (~flag);
- }
-
- ///
- /// Sets a bit-field to either on or off for the specified flag.
- ///
- /// Enumeration with Flags attribute
- /// Flagged variable
- /// Flag to change
- /// bool
- /// The flagged variable with the flag changed
- public static long SetFlag(T bitField, T flag, bool @on)
- where T : struct
- {
- return SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), @on);
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ internal static class FlagUtility
+ {
+ ///
+ /// Returns true if the flag is set on the specified bit field.
+ /// Currently only works with 32-bit bitfields.
+ ///
+ /// Enumeration with Flags attribute
+ /// Flagged variable
+ /// Flag to test
+ ///
+ public static bool HasFlag(long bitField, T flag)
+ where T : struct
+ {
+ return HasFlag(bitField, flag);
+ }
+
+ ///
+ /// Returns true if the flag is set on the specified bit field.
+ /// Currently only works with 32-bit bitfields.
+ ///
+ /// Enumeration with Flags attribute
+ /// Flagged variable
+ /// Flag to test
+ ///
+ public static bool HasFlag(ulong bitField, T flag)
+ where T : struct
+ {
+ return HasFlag(bitField, flag);
+ }
+
+ ///
+ /// Returns true if the flag is set on the specified bit field.
+ /// Currently only works with 32-bit bitfields.
+ ///
+ /// Flagged variable
+ /// Flag to test
+ ///
+ public static bool HasFlag(ulong bitField, ulong flag)
+ {
+ return ((bitField & flag) == flag);
+ }
+
+ public static bool HasFlag(short bitField, short flag)
+ {
+ return ((bitField & flag) == flag);
+ }
+
+ ///
+ /// Returns true if the flag is set on the specified bit field.
+ /// Currently only works with 32-bit bitfields.
+ ///
+ /// Enumeration with Flags attribute
+ /// Flagged variable
+ /// Flag to test
+ ///
+ public static bool HasFlag(T bitField, T flag)
+ where T : struct
+ {
+ return HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag));
+ }
+
+ ///
+ /// Returns true if the flag is set on the specified bit field.
+ /// Currently only works with 32-bit bitfields.
+ ///
+ /// Flagged variable
+ /// Flag to test
+ ///
+ public static bool HasFlag(long bitField, long flag)
+ {
+ return ((bitField & flag) == flag);
+ }
+
+
+ ///
+ /// Sets a bit-field to either on or off for the specified flag.
+ ///
+ /// Flagged variable
+ /// Flag to change
+ /// bool
+ /// The flagged variable with the flag changed
+ public static long SetFlag(long bitField, long flag, bool @on)
+ {
+ if (@on)
+ {
+ return bitField | flag;
+ }
+ return bitField & (~flag);
+ }
+
+ ///
+ /// Sets a bit-field to either on or off for the specified flag.
+ ///
+ /// Enumeration with Flags attribute
+ /// Flagged variable
+ /// Flag to change
+ /// bool
+ /// The flagged variable with the flag changed
+ public static long SetFlag(T bitField, T flag, bool @on)
+ where T : struct
+ {
+ return SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), @on);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/GZip/GZipEntry.cs b/src/SharpCompress/Common/GZip/GZipEntry.cs
similarity index 95%
rename from SharpCompress/Common/GZip/GZipEntry.cs
rename to src/SharpCompress/Common/GZip/GZipEntry.cs
index f6408f5c..3d3a23e6 100644
--- a/SharpCompress/Common/GZip/GZipEntry.cs
+++ b/src/SharpCompress/Common/GZip/GZipEntry.cs
@@ -1,86 +1,86 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace SharpCompress.Common.GZip
-{
- public class GZipEntry : Entry
- {
- private readonly GZipFilePart filePart;
-
- internal GZipEntry(GZipFilePart filePart)
- {
- this.filePart = filePart;
- }
-
- public override CompressionType CompressionType
- {
- get { return CompressionType.GZip; }
- }
-
- public override long Crc
- {
- get { return 0; }
- }
-
- public override string Key
- {
- get { return filePart.FilePartName; }
- }
-
- public override long CompressedSize
- {
- get { return 0; }
- }
-
- public override long Size
- {
- get { return 0; }
- }
-
- public override DateTime? LastModifiedTime
- {
- get { return filePart.DateModified; }
- }
-
- public override DateTime? CreatedTime
- {
- get { return null; }
- }
-
- public override DateTime? LastAccessedTime
- {
- get { return null; }
- }
-
- public override DateTime? ArchivedTime
- {
- get { return null; }
- }
-
- public override bool IsEncrypted
- {
- get { return false; }
- }
-
- public override bool IsDirectory
- {
- get { return false; }
- }
-
- public override bool IsSplit
- {
- get { return false; }
- }
-
- internal override IEnumerable Parts
- {
- get { return filePart.AsEnumerable(); }
- }
-
- internal static IEnumerable GetEntries(Stream stream)
- {
- yield return new GZipEntry(new GZipFilePart(stream));
- }
- }
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace SharpCompress.Common.GZip
+{
+ public class GZipEntry : Entry
+ {
+ private readonly GZipFilePart filePart;
+
+ internal GZipEntry(GZipFilePart filePart)
+ {
+ this.filePart = filePart;
+ }
+
+ public override CompressionType CompressionType
+ {
+ get { return CompressionType.GZip; }
+ }
+
+ public override long Crc
+ {
+ get { return 0; }
+ }
+
+ public override string Key
+ {
+ get { return filePart.FilePartName; }
+ }
+
+ public override long CompressedSize
+ {
+ get { return 0; }
+ }
+
+ public override long Size
+ {
+ get { return 0; }
+ }
+
+ public override DateTime? LastModifiedTime
+ {
+ get { return filePart.DateModified; }
+ }
+
+ public override DateTime? CreatedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? LastAccessedTime
+ {
+ get { return null; }
+ }
+
+ public override DateTime? ArchivedTime
+ {
+ get { return null; }
+ }
+
+ public override bool IsEncrypted
+ {
+ get { return false; }
+ }
+
+ public override bool IsDirectory
+ {
+ get { return false; }
+ }
+
+ public override bool IsSplit
+ {
+ get { return false; }
+ }
+
+ internal override IEnumerable Parts
+ {
+ get { return filePart.AsEnumerable(); }
+ }
+
+ internal static IEnumerable GetEntries(Stream stream)
+ {
+ yield return new GZipEntry(new GZipFilePart(stream));
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs
similarity index 96%
rename from SharpCompress/Common/GZip/GZipFilePart.cs
rename to src/SharpCompress/Common/GZip/GZipFilePart.cs
index 673e50ea..2ef0679c 100644
--- a/SharpCompress/Common/GZip/GZipFilePart.cs
+++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs
@@ -1,104 +1,104 @@
-using System;
-using System.IO;
-using SharpCompress.Common.Tar.Headers;
-using SharpCompress.Compressor;
-using SharpCompress.Compressor.Deflate;
-using SharpCompress.Converter;
-
-namespace SharpCompress.Common.GZip
-{
- internal class GZipFilePart : FilePart
- {
- private string name;
- private readonly Stream stream;
-
- internal GZipFilePart(Stream stream)
- {
- ReadAndValidateGzipHeader(stream);
- this.stream = stream;
- }
-
- internal DateTime? DateModified { get; private set; }
-
- internal override string FilePartName
- {
- get { return name; }
- }
-
- internal override Stream GetCompressedStream()
- {
- return new DeflateStream(stream, CompressionMode.Decompress, CompressionLevel.Default, false);
- }
-
- internal override Stream GetRawStream()
- {
- return stream;
- }
-
- private void ReadAndValidateGzipHeader(Stream stream)
- {
- // read the header on the first read
- byte[] header = new byte[10];
- int n = stream.Read(header, 0, header.Length);
-
- // workitem 8501: handle edge case (decompress empty stream)
- if (n == 0)
- return;
-
- if (n != 10)
- throw new ZlibException("Not a valid GZIP stream.");
-
- if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
- throw new ZlibException("Bad GZIP header.");
-
- Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
- DateModified = TarHeader.Epoch.AddSeconds(timet);
- if ((header[3] & 0x04) == 0x04)
- {
- // read and discard extra field
- n = stream.Read(header, 0, 2); // 2-byte length field
-
- Int16 extraLength = (Int16) (header[0] + header[1]*256);
- byte[] extra = new byte[extraLength];
- n = stream.Read(extra, 0, extra.Length);
- if (n != extraLength)
- {
- throw new ZlibException("Unexpected end-of-file reading GZIP header.");
- }
- }
- if ((header[3] & 0x08) == 0x08)
- name = ReadZeroTerminatedString(stream);
- if ((header[3] & 0x10) == 0x010)
- ReadZeroTerminatedString(stream);
- if ((header[3] & 0x02) == 0x02)
- stream.ReadByte(); // CRC16, ignore
- }
-
-
- private static string ReadZeroTerminatedString(Stream stream)
- {
- byte[] buf1 = new byte[1];
- var list = new System.Collections.Generic.List();
- bool done = false;
- do
- {
- // workitem 7740
- int n = stream.Read(buf1, 0, 1);
- if (n != 1)
- {
- throw new ZlibException("Unexpected EOF reading GZIP header.");
- }
- if (buf1[0] == 0)
- {
- done = true;
- }
- else
- {
- list.Add(buf1[0]);
- }
- } while (!done);
- byte[] a = list.ToArray();
- return ArchiveEncoding.Default.GetString(a, 0, a.Length);
- }
- }
+using System;
+using System.IO;
+using SharpCompress.Common.Tar.Headers;
+using SharpCompress.Compressor;
+using SharpCompress.Compressor.Deflate;
+using SharpCompress.Converter;
+
+namespace SharpCompress.Common.GZip
+{
+ internal class GZipFilePart : FilePart
+ {
+ private string name;
+ private readonly Stream stream;
+
+ internal GZipFilePart(Stream stream)
+ {
+ ReadAndValidateGzipHeader(stream);
+ this.stream = stream;
+ }
+
+ internal DateTime? DateModified { get; private set; }
+
+ internal override string FilePartName
+ {
+ get { return name; }
+ }
+
+ internal override Stream GetCompressedStream()
+ {
+ return new DeflateStream(stream, CompressionMode.Decompress, CompressionLevel.Default, false);
+ }
+
+ internal override Stream GetRawStream()
+ {
+ return stream;
+ }
+
+ private void ReadAndValidateGzipHeader(Stream stream)
+ {
+ // read the header on the first read
+ byte[] header = new byte[10];
+ int n = stream.Read(header, 0, header.Length);
+
+ // workitem 8501: handle edge case (decompress empty stream)
+ if (n == 0)
+ return;
+
+ if (n != 10)
+ throw new ZlibException("Not a valid GZIP stream.");
+
+ if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
+ throw new ZlibException("Bad GZIP header.");
+
+ Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
+ DateModified = TarHeader.Epoch.AddSeconds(timet);
+ if ((header[3] & 0x04) == 0x04)
+ {
+ // read and discard extra field
+ n = stream.Read(header, 0, 2); // 2-byte length field
+
+ Int16 extraLength = (Int16) (header[0] + header[1]*256);
+ byte[] extra = new byte[extraLength];
+ n = stream.Read(extra, 0, extra.Length);
+ if (n != extraLength)
+ {
+ throw new ZlibException("Unexpected end-of-file reading GZIP header.");
+ }
+ }
+ if ((header[3] & 0x08) == 0x08)
+ name = ReadZeroTerminatedString(stream);
+ if ((header[3] & 0x10) == 0x010)
+ ReadZeroTerminatedString(stream);
+ if ((header[3] & 0x02) == 0x02)
+ stream.ReadByte(); // CRC16, ignore
+ }
+
+
+ private static string ReadZeroTerminatedString(Stream stream)
+ {
+ byte[] buf1 = new byte[1];
+ var list = new System.Collections.Generic.List();
+ bool done = false;
+ do
+ {
+ // workitem 7740
+ int n = stream.Read(buf1, 0, 1);
+ if (n != 1)
+ {
+ throw new ZlibException("Unexpected EOF reading GZIP header.");
+ }
+ if (buf1[0] == 0)
+ {
+ done = true;
+ }
+ else
+ {
+ list.Add(buf1[0]);
+ }
+ } while (!done);
+ byte[] a = list.ToArray();
+ return ArchiveEncoding.Default.GetString(a, 0, a.Length);
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs
similarity index 90%
rename from SharpCompress/Common/GZip/GZipVolume.cs
rename to src/SharpCompress/Common/GZip/GZipVolume.cs
index 0b49f649..639edaf5 100644
--- a/SharpCompress/Common/GZip/GZipVolume.cs
+++ b/src/SharpCompress/Common/GZip/GZipVolume.cs
@@ -1,29 +1,29 @@
-using System.IO;
-
-namespace SharpCompress.Common.GZip
-{
- public class GZipVolume : Volume
- {
- public GZipVolume(Stream stream, Options options)
- : base(stream, options)
- {
- }
-
-#if !PORTABLE && !NETFX_CORE
- public GZipVolume(FileInfo fileInfo, Options options)
- : base(fileInfo.OpenRead(), options)
- {
- }
-#endif
-
- public override bool IsFirstVolume
- {
- get { return true; }
- }
-
- public override bool IsMultiVolume
- {
- get { return true; }
- }
- }
+using System.IO;
+
+namespace SharpCompress.Common.GZip
+{
+ public class GZipVolume : Volume
+ {
+ public GZipVolume(Stream stream, Options options)
+ : base(stream, options)
+ {
+ }
+
+#if !NO_FILE
+ public GZipVolume(FileInfo fileInfo, Options options)
+ : base(fileInfo.OpenRead(), options)
+ {
+ }
+#endif
+
+ public override bool IsFirstVolume
+ {
+ get { return true; }
+ }
+
+ public override bool IsMultiVolume
+ {
+ get { return true; }
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/IEntry.Extensions.cs b/src/SharpCompress/Common/IEntry.Extensions.cs
similarity index 96%
rename from SharpCompress/Common/IEntry.Extensions.cs
rename to src/SharpCompress/Common/IEntry.Extensions.cs
index 8385c7db..f39b4dde 100644
--- a/SharpCompress/Common/IEntry.Extensions.cs
+++ b/src/SharpCompress/Common/IEntry.Extensions.cs
@@ -1,48 +1,49 @@
-using System;
-using System.IO;
-
-namespace SharpCompress.Common
-{
- internal static class IEntryExtensions
- {
- internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
- ExtractOptions options)
- {
- if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
- {
- FileInfo nf = new FileInfo(destinationFileName);
- if (!nf.Exists)
- {
- return;
- }
-
- // update file time to original packed time
- if (options.HasFlag(ExtractOptions.PreserveFileTime))
- {
- if (entry.CreatedTime.HasValue)
- {
- nf.CreationTime = entry.CreatedTime.Value;
- }
-
- if (entry.LastModifiedTime.HasValue)
- {
- nf.LastWriteTime = entry.LastModifiedTime.Value;
- }
-
- if (entry.LastAccessedTime.HasValue)
- {
- nf.LastAccessTime = entry.LastAccessedTime.Value;
- }
- }
-
- if (options.HasFlag(ExtractOptions.PreserveAttributes))
- {
- if (entry.Attrib.HasValue)
- {
- nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
- }
- }
- }
- }
- }
-}
+#if !NO_FILE
+using System.IO;
+
+namespace SharpCompress.Common
+{
+ internal static class IEntryExtensions
+ {
+ internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
+ ExtractOptions options)
+ {
+ if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
+ {
+ FileInfo nf = new FileInfo(destinationFileName);
+ if (!nf.Exists)
+ {
+ return;
+ }
+
+ // update file time to original packed time
+ if (options.HasFlag(ExtractOptions.PreserveFileTime))
+ {
+ if (entry.CreatedTime.HasValue)
+ {
+ nf.CreationTime = entry.CreatedTime.Value;
+ }
+
+ if (entry.LastModifiedTime.HasValue)
+ {
+ nf.LastWriteTime = entry.LastModifiedTime.Value;
+ }
+
+ if (entry.LastAccessedTime.HasValue)
+ {
+ nf.LastAccessTime = entry.LastAccessedTime.Value;
+ }
+ }
+
+ if (options.HasFlag(ExtractOptions.PreserveAttributes))
+ {
+ if (entry.Attrib.HasValue)
+ {
+ nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
+ }
+ }
+ }
+ }
+ }
+}
+#endif
diff --git a/SharpCompress/Common/IEntry.cs b/src/SharpCompress/Common/IEntry.cs
similarity index 96%
rename from SharpCompress/Common/IEntry.cs
rename to src/SharpCompress/Common/IEntry.cs
index 22a18c50..ac15828c 100644
--- a/SharpCompress/Common/IEntry.cs
+++ b/src/SharpCompress/Common/IEntry.cs
@@ -1,21 +1,21 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public interface IEntry
- {
- CompressionType CompressionType { get; }
- DateTime? ArchivedTime { get; }
- long CompressedSize { get; }
- long Crc { get; }
- DateTime? CreatedTime { get; }
- string Key { get; }
- bool IsDirectory { get; }
- bool IsEncrypted { get; }
- bool IsSplit { get; }
- DateTime? LastAccessedTime { get; }
- DateTime? LastModifiedTime { get; }
- long Size { get; }
- int? Attrib { get; }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public interface IEntry
+ {
+ CompressionType CompressionType { get; }
+ DateTime? ArchivedTime { get; }
+ long CompressedSize { get; }
+ long Crc { get; }
+ DateTime? CreatedTime { get; }
+ string Key { get; }
+ bool IsDirectory { get; }
+ bool IsEncrypted { get; }
+ bool IsSplit { get; }
+ DateTime? LastAccessedTime { get; }
+ DateTime? LastModifiedTime { get; }
+ long Size { get; }
+ int? Attrib { get; }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/IExtractionListener.cs b/src/SharpCompress/Common/IExtractionListener.cs
similarity index 97%
rename from SharpCompress/Common/IExtractionListener.cs
rename to src/SharpCompress/Common/IExtractionListener.cs
index b46a37e4..b6fb50fc 100644
--- a/SharpCompress/Common/IExtractionListener.cs
+++ b/src/SharpCompress/Common/IExtractionListener.cs
@@ -1,8 +1,8 @@
-namespace SharpCompress.Common
-{
- internal interface IExtractionListener
- {
- void FireFilePartExtractionBegin(string name, long size, long compressedSize);
- void FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes);
- }
+namespace SharpCompress.Common
+{
+ internal interface IExtractionListener
+ {
+ void FireFilePartExtractionBegin(string name, long size, long compressedSize);
+ void FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes);
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/IVolume.cs b/src/SharpCompress/Common/IVolume.cs
similarity index 77%
rename from SharpCompress/Common/IVolume.cs
rename to src/SharpCompress/Common/IVolume.cs
index 6482e575..a8d02252 100644
--- a/SharpCompress/Common/IVolume.cs
+++ b/src/SharpCompress/Common/IVolume.cs
@@ -1,11 +1,11 @@
-using System;
-#if !PORTABLE && !NETFX_CORE
-using System.IO;
-#endif
-
-namespace SharpCompress.Common
-{
- public interface IVolume : IDisposable
- {
- }
+using System;
+#if !NO_FILE
+using System.IO;
+#endif
+
+namespace SharpCompress.Common
+{
+ public interface IVolume : IDisposable
+ {
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/IncompleteArchiveException.cs b/src/SharpCompress/Common/IncompleteArchiveException.cs
similarity index 96%
rename from SharpCompress/Common/IncompleteArchiveException.cs
rename to src/SharpCompress/Common/IncompleteArchiveException.cs
index 21b24cfd..78d567f4 100644
--- a/SharpCompress/Common/IncompleteArchiveException.cs
+++ b/src/SharpCompress/Common/IncompleteArchiveException.cs
@@ -1,10 +1,10 @@
-namespace SharpCompress.Common
-{
- public class IncompleteArchiveException : ArchiveException
- {
- public IncompleteArchiveException(string message)
- : base(message)
- {
- }
- }
+namespace SharpCompress.Common
+{
+ public class IncompleteArchiveException : ArchiveException
+ {
+ public IncompleteArchiveException(string message)
+ : base(message)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/InvalidFormatException.cs b/src/SharpCompress/Common/InvalidFormatException.cs
similarity index 95%
rename from SharpCompress/Common/InvalidFormatException.cs
rename to src/SharpCompress/Common/InvalidFormatException.cs
index d0b16865..fa141cb4 100644
--- a/SharpCompress/Common/InvalidFormatException.cs
+++ b/src/SharpCompress/Common/InvalidFormatException.cs
@@ -1,17 +1,17 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class InvalidFormatException : ExtractionException
- {
- public InvalidFormatException(string message)
- : base(message)
- {
- }
-
- public InvalidFormatException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class InvalidFormatException : ExtractionException
+ {
+ public InvalidFormatException(string message)
+ : base(message)
+ {
+ }
+
+ public InvalidFormatException(string message, Exception inner)
+ : base(message, inner)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/MultiVolumeExtractionException.cs b/src/SharpCompress/Common/MultiVolumeExtractionException.cs
similarity index 95%
rename from SharpCompress/Common/MultiVolumeExtractionException.cs
rename to src/SharpCompress/Common/MultiVolumeExtractionException.cs
index a0ea22ac..d9b97fa3 100644
--- a/SharpCompress/Common/MultiVolumeExtractionException.cs
+++ b/src/SharpCompress/Common/MultiVolumeExtractionException.cs
@@ -1,17 +1,17 @@
-using System;
-
-namespace SharpCompress.Common
-{
- public class MultiVolumeExtractionException : ExtractionException
- {
- public MultiVolumeExtractionException(string message)
- : base(message)
- {
- }
-
- public MultiVolumeExtractionException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
+using System;
+
+namespace SharpCompress.Common
+{
+ public class MultiVolumeExtractionException : ExtractionException
+ {
+ public MultiVolumeExtractionException(string message)
+ : base(message)
+ {
+ }
+
+ public MultiVolumeExtractionException(string message, Exception inner)
+ : base(message, inner)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/MultipartStreamRequiredException.cs b/src/SharpCompress/Common/MultipartStreamRequiredException.cs
similarity index 96%
rename from SharpCompress/Common/MultipartStreamRequiredException.cs
rename to src/SharpCompress/Common/MultipartStreamRequiredException.cs
index 2c441407..cf030ed6 100644
--- a/SharpCompress/Common/MultipartStreamRequiredException.cs
+++ b/src/SharpCompress/Common/MultipartStreamRequiredException.cs
@@ -1,10 +1,10 @@
-namespace SharpCompress.Common
-{
- public class MultipartStreamRequiredException : ExtractionException
- {
- public MultipartStreamRequiredException(string message)
- : base(message)
- {
- }
- }
+namespace SharpCompress.Common
+{
+ public class MultipartStreamRequiredException : ExtractionException
+ {
+ public MultipartStreamRequiredException(string message)
+ : base(message)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/SharpCompress/Common/Options.cs b/src/SharpCompress/Common/Options.cs
similarity index 96%
rename from SharpCompress/Common/Options.cs
rename to src/SharpCompress/Common/Options.cs
index d7d4b372..32ec2d0c 100644
--- a/SharpCompress/Common/Options.cs
+++ b/src/SharpCompress/Common/Options.cs
@@ -1,23 +1,23 @@
-using System;
-
-namespace SharpCompress.Common
-{
- [Flags]
- public enum Options
- {
- ///