Compare commits

...

30 Commits
0.11 ... 0.11.2

Author SHA1 Message Date
Adam Hathcock
1aa0498e5d update nuspec 2015-11-30 19:40:24 +00:00
Adam Hathcock
1ce5e15fd2 Minor cleanup 2015-11-30 19:40:16 +00:00
Adam Hathcock
b40131736a Merge pull request #103 from pappe82/android-compatibility
Zip entry header version for Deflate compression set to 20
2015-11-30 19:37:38 +00:00
pappe82
c2b15b9c09 Zip entry header version for Deflate compression set to 20
The java runtime on Android cannot process file entries with the fixed
version 63 - it can only process entries up to version 20, which should
be fine if the entry was compressed using deflate.
2015-11-30 14:43:28 +01:00
Adam Hathcock
27a4f78712 version 0.11.2 2015-11-20 18:59:43 +00:00
Adam Hathcock
2b5ee6e8cb resharper update 2015-11-20 18:59:29 +00:00
Adam Hathcock
cd8ea28576 last write time shouldn't equal...right? 2015-11-20 18:59:15 +00:00
Adam Hathcock
b2b6934499 Merge pull request #101 from twirpx/master
Non-compilable statements + zip archive handling
2015-11-19 16:46:26 +00:00
twirpx
0f12a073af Eliminated "throw - catch all" logic in ZipArchive 2015-11-19 21:08:55 +05:00
twirpx
18bd810228 Fixed non-compilable statements 2015-11-19 21:07:52 +05:00
twirpx
13bbb202c7 Changed MAX_ITERATIONS_FOR_DIRECTORY_HEADER to deal with archives that have larger comments 2015-11-19 21:06:56 +05:00
Adam Hathcock
9a638e7aa5 Merge pull request #97 from Icenium/natanasova/add-explicit-compressioninfo
Add explicit compressioninfo when writing file to zip
2015-10-01 09:33:26 -07:00
Adam Hathcock
7a11dc4385 Merge pull request #96 from Icenium/natanasova/fix-extract-options-as-flag
Use enum as flag correctly
2015-10-01 09:30:46 -07:00
Nadya Atanasova
66816ce390 Add explicit compressioninfo when writing file to zip 2015-10-01 17:15:37 +03:00
Nadya Atanasova
5d8bd7b69b Use enum as flag correctly
Check PreserveFileTime when file times are initialized.
2015-10-01 17:02:58 +03:00
Adam Hathcock
0132c85ec7 Merge pull request #83 from haykpetros/issue_80
Added additional check to make sure that data is properly copied to a…
2015-08-30 09:46:38 +01:00
haykpetros
9bf5df72a6 Added additional check to make sure that data is properly copied to array regardless fo computer/CPU platform (little-endian or big-endian). In case of big-endian platform intermediate array will be reversed prior to copying to destination array. 2015-08-05 05:27:30 -07:00
Adam Hathcock
91fc241358 Merge pull request #82 from haykpetros/issue_79
Issue 79
2015-08-04 15:05:37 +01:00
haykpetros
35a8b444b8 I feel there is no need to use unsafe version, so conditional compilation has been removed and only safe version kept. 2015-08-04 03:47:09 -07:00
haykpetros
2e928e86fd Removed unused method. 2015-08-04 03:24:59 -07:00
Adam Hathcock
6648f33c4e Merge pull request #81 from haykpetros/issue_78
Move closing parentheses to where they should be, so build does not b…
2015-08-04 10:05:17 +01:00
haykpetros
2a70ec8100 Move closing parentheses to where they should be, so build does not break for non-DEBUG configurations. 2015-08-03 13:11:13 -07:00
Adam Hathcock
05e0d591a5 Merge pull request #72 from hodm/master
Extract Options And Total Sizes
2015-07-27 10:07:22 +01:00
Adam Hathcock
1d30a1b51d Update README 2015-07-27 10:03:39 +01:00
Adam Hathcock
315c138c05 Removing .NET 2.0 support and LinqBridge dies a firey death 2015-07-27 09:48:36 +01:00
hodm
b0c514d87c Extract Options And Total Sizes
Fixed TotalSize For 7z
added TotalUncompressSize Tested for 7z
this enables to show progress for the entire archive
Added 2 Extract Options: PreserveFileTime And PreserveAttributes.
Put All the Log Command under DEBUG Condition.
2015-07-26 23:36:28 +03:00
Adam Hathcock
8e5cb77af2 Merge pull request #69 from pnewman8/master
Skip entry stream on dispose
2015-07-20 16:27:55 +01:00
Paul Newman
8faebc78d0 Cancel moved from EntryStream to Reader
Relates to previous commit. Following discussion with Adam, moved the Cancel() to the reader.

Example:

while (reader.MoveToNextEntry())
{
  using (var data = new StreamReader(reader.OpenEntryStream()))
  {
    try
    {
      DoSomething(data.ReadLine());
    }
    catch
    {
      reader.Cancel();
      throw;
    }
  }
}
2015-07-15 18:13:46 +01:00
Paul Newman
afff386622 Skip entry stream on dispose
Until now the caller had to completely consume each entry stream, or call SkipEntry(), before disposing the stream. If not, exception was thrown: "EntryStream has not been fully consumed". Hugely inconvenient; a user-thrown exception inside a "using (EntryStream)" block would be discarded.

Now automatically skips the entry on dispose.

Added method EntryStream.Cancel(). Call this if entry stream is unfinished, and no further entries are required. Helps with efficiency, as it avoids reading data that is not needed.
2015-07-15 13:44:20 +01:00
Adam Hathcock
9eb43156e8 Update license URL 2015-06-12 12:06:21 +01:00
40 changed files with 537 additions and 582 deletions

View File

@@ -2,11 +2,11 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>sharpcompress</id>
<version>0.11.0</version>
<version>0.11.2</version>
<title>SharpCompress - Pure C# Decompression/Compression</title>
<authors>Adam Hathcock</authors>
<owners>Adam Hathcock</owners>
<licenseUrl>http://sharpcompress.codeplex.com/license</licenseUrl>
<licenseUrl>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/adamhathcock/sharpcompress</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>SharpCompress is a compression library for .NET/Mono/Silverlight/WP7/WindowsStore that can unrar, decompress 7zip, zip/unzip, tar/untar bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</description>
@@ -14,16 +14,11 @@
<language>en-US</language>
<tags>rar unrar zip unzip bzip2 gzip tar 7zip</tags>
<dependencies>
<group />
<group targetFramework="net20">
<dependency id="LinqBridge" version="1.3.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\bin\Full\SharpCompress.dll" target="lib\net40\SharpCompress.dll" />
<file src="..\bin\WindowsStore\SharpCompress.dll" target="lib\netcore45\SharpCompress.dll" />
<file src="..\bin\Portable\SharpCompress.dll" target="lib\portable-net4+sl5+wp8+win8\SharpCompress.dll" />
<file src="..\bin\NET2\SharpCompress.dll" target="lib\net20\SharpCompress.dll" />
</files>
</package>

View File

@@ -21,6 +21,11 @@ TODOs (always lots):
* Zip64
* Multi-volume Zip support.
Version 0.11.1:
==============
- Added Cancel on IReader
- Removed .NET 2.0 support and LinqBridge dependency
Version 0.11:
==============
- Been over a year, contains mainly fixes from contributors!

View File

@@ -125,6 +125,55 @@ namespace SharpCompress.Test
private long? entryTotal;
private long partTotal;
private long totalSize;
protected void ArchiveFileReadEx(string testArchive)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
ArchiveFileReadEx(testArchive.AsEnumerable());
}
/// <summary>
/// Demonstrate the TotalUncompressSize property, and the ExtractOptions.PreserveFileTime and ExtractOptions.PreserveAttributes extract options
/// </summary>
protected void ArchiveFileReadEx(IEnumerable<string> testArchives)
{
foreach (var path in testArchives)
{
ResetScratch();
using (var archive = ArchiveFactory.Open(path))
{
this.totalSize = archive.TotalUncompressSize;
archive.EntryExtractionBegin += Archive_EntryExtractionBeginEx;
archive.EntryExtractionEnd += Archive_EntryExtractionEndEx;
archive.CompressedBytesRead += Archive_CompressedBytesReadEx;
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH,
ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite | ExtractOptions.PreserveFileTime | ExtractOptions.PreserveAttributes);
}
}
VerifyFilesEx();
}
}
private void Archive_EntryExtractionEndEx(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e)
{
this.partTotal += e.Item.Size;
}
private void Archive_CompressedBytesReadEx(object sender, CompressedBytesReadEventArgs e)
{
string percentage = this.entryTotal.HasValue ? this.CreatePercentage(e.CompressedBytesRead, this.entryTotal.Value).ToString() : "-";
string tortalPercentage = this.CreatePercentage(this.partTotal + e.CompressedBytesRead, this.totalSize).ToString();
Console.WriteLine(@"Read Compressed File Progress: {0}% Total Progress {1}%", percentage, tortalPercentage);
}
private void Archive_EntryExtractionBeginEx(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e)
{
this.entryTotal = e.Item.Size;
}
private int CreatePercentage(long n, long d)
{

View File

@@ -61,6 +61,11 @@ namespace SharpCompress.Test
ArchiveFileRead("7Zip.BZip2.7z");
}
[TestMethod]
public void SevenZipArchive_LZMA_Time_Attributes_PathRead()
{
ArchiveFileReadEx("7Zip.LZMA.7z");
}
[TestMethod]
[ExpectedException(typeof(IndexOutOfRangeException))]

View File

@@ -78,6 +78,21 @@ namespace SharpCompress.Test
}
}
/// <summary>
/// Verifies the files also check modified time and attributes.
/// </summary>
public void VerifyFilesEx()
{
if (UseExtensionInsteadOfNameToVerify)
{
VerifyFilesByExtensionEx();
}
else
{
VerifyFilesByNameEx();
}
}
protected void VerifyFilesByName()
{
var extracted =
@@ -97,6 +112,52 @@ namespace SharpCompress.Test
}
}
/// <summary>
/// Verifies the files by name also check modified time and attributes.
/// </summary>
protected void VerifyFilesByNameEx()
{
var extracted =
Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories)
.ToLookup(path => path.Substring(SCRATCH_FILES_PATH.Length));
var original =
Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)
.ToLookup(path => path.Substring(ORIGINAL_FILES_PATH.Length));
Assert.AreEqual(extracted.Count, original.Count);
foreach (var orig in original)
{
Assert.IsTrue(extracted.Contains(orig.Key));
CompareFilesByPath(orig.Single(), extracted[orig.Key].Single());
CompareFilesByTimeAndAttribut(orig.Single(), extracted[orig.Key].Single());
}
}
/// <summary>
/// Verifies the files by extension also check modified time and attributes.
/// </summary>
protected void VerifyFilesByExtensionEx()
{
var extracted =
Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories)
.ToLookup(path => Path.GetExtension(path));
var original =
Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)
.ToLookup(path => Path.GetExtension(path));
Assert.AreEqual(extracted.Count, original.Count);
foreach (var orig in original)
{
Assert.IsTrue(extracted.Contains(orig.Key));
CompareFilesByPath(orig.Single(), extracted[orig.Key].Single());
CompareFilesByTimeAndAttribut(orig.Single(), extracted[orig.Key].Single());
}
}
protected bool UseExtensionInsteadOfNameToVerify { get; set; }
protected void VerifyFilesByExtension()
@@ -137,6 +198,14 @@ namespace SharpCompress.Test
}
}
protected void CompareFilesByTimeAndAttribut(string file1, string file2)
{
FileInfo fi1 = new FileInfo(file1);
FileInfo fi2 = new FileInfo(file2);
Assert.AreNotEqual(fi1.LastWriteTime, fi2.LastWriteTime);
Assert.AreEqual(fi1.Attributes, fi2.Attributes);
}
protected void CompareArchivesByPath(string file1, string file2)
{
using (var archive1 = ReaderFactory.Open(File.OpenRead(file1), Options.None))

View File

@@ -22,8 +22,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.PortableTest"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Test.Portable", "SharpCompress.Test\SharpCompress.Test.Portable.csproj", "{E9C3C94B-FB27-4B4F-B225-57513C254D37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.NET2", "SharpCompress\SharpCompress.NET2.csproj", "{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Unsigned", "SharpCompress\SharpCompress.Unsigned.csproj", "{27D535CB-2FD3-4621-8C9A-46161FC77A5D}"
EndProject
Global
@@ -56,10 +54,6 @@ Global
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Release|Any CPU.Build.0 = Release|Any CPU
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Release|Any CPU.Build.0 = Release|Any CPU
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@@ -84,7 +84,6 @@ namespace SharpCompress.Archive
/// <summary>
/// Returns an ReadOnlyCollection of all the RarArchiveEntries across the one or many parts of the RarArchive.
/// </summary>
/// <returns></returns>
public virtual ICollection<TEntry> Entries
{
get { return lazyEntries; }
@@ -93,7 +92,6 @@ namespace SharpCompress.Archive
/// <summary>
/// Returns an ReadOnlyCollection of all the RarArchiveVolumes across the one or many parts of the RarArchive.
/// </summary>
/// <returns></returns>
public ICollection<TVolume> Volumes
{
get { return lazyVolumes; }
@@ -102,11 +100,19 @@ namespace SharpCompress.Archive
/// <summary>
/// The total size of the files compressed in the archive.
/// </summary>
public long TotalSize
public virtual long TotalSize
{
get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); }
}
/// <summary>
/// The total size of the files as uncompressed in the archive.
/// </summary>
public virtual long TotalUncompressSize
{
get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); }
}
protected abstract IEnumerable<TVolume> LoadVolumes(IEnumerable<Stream> streams, Options options);
protected abstract IEnumerable<TEntry> LoadEntries(IEnumerable<TVolume> volumes);

View File

@@ -14,7 +14,6 @@ namespace SharpCompress.Archive
event EventHandler<FilePartExtractionBeginEventArgs> FilePartExtractionBegin;
IEnumerable<IArchiveEntry> Entries { get; }
long TotalSize { get; }
IEnumerable<IVolume> Volumes { get; }
ArchiveType Type { get; }
@@ -24,7 +23,6 @@ namespace SharpCompress.Archive
/// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
/// extracted sequentially for the best performance.
/// </summary>
/// <returns></returns>
IReader ExtractAllEntries();
/// <summary>
@@ -37,5 +35,15 @@ namespace SharpCompress.Archive
/// This checks to see if all the known entries have IsComplete = true
/// </summary>
bool IsComplete { get; }
/// <summary>
/// The total size of the files compressed in the archive.
/// </summary>
long TotalSize { get; }
/// <summary>
/// The total size of the files as uncompressed in the archive.
/// </summary>
long TotalUncompressSize { get; }
}
}

View File

@@ -83,6 +83,40 @@ namespace SharpCompress.Archive
{
entry.WriteTo(fs);
}
if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
{
// update file time to original packed time
FileInfo nf = new FileInfo(destinationFileName);
if (nf.Exists)
{
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.CreatedTime.Value;
}
}
if (options.HasFlag(ExtractOptions.PreserveAttributes))
{
if (entry.Attrib.HasValue)
{
nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
}
}
}
}
}
#endif
}

View File

@@ -188,6 +188,15 @@ namespace SharpCompress.Archive.SevenZip
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<SevenZipEntry, SevenZipVolume>
{
private readonly SevenZipArchive archive;
@@ -236,7 +245,7 @@ namespace SharpCompress.Archive.SevenZip
protected override EntryStream GetEntryStream()
{
return new EntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
}
}
}

View File

@@ -116,7 +116,7 @@ namespace SharpCompress.Archive.Zip
try
{
ZipHeader header =
headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x != null && x.ZipHeaderType != ZipHeaderType.Split);
if (header == null)
{
return false;

View File

@@ -46,7 +46,7 @@ namespace SharpCompress.Common
public abstract DateTime? LastAccessedTime { get; }
/// <summary>
/// The entry time whend archived, if recorded
/// The entry time when archived, if recorded
/// </summary>
public abstract DateTime? ArchivedTime { get; }
@@ -70,7 +70,16 @@ namespace SharpCompress.Common
internal virtual void Close()
{
}
/// <summary>
/// Entry file attribute.
/// </summary>
public virtual int? Attrib
{
get { throw new NotImplementedException(); }
}
}
}

View File

@@ -1,16 +1,19 @@
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(Stream stream)
internal EntryStream(IReader reader, Stream stream)
{
this.Reader = reader;
this.stream = stream;
}
@@ -28,10 +31,9 @@ namespace SharpCompress.Common
protected override void Dispose(bool disposing)
{
if (!completed)
if (!(completed || Reader.Cancelled))
{
throw new InvalidOperationException(
"EntryStream has not been fully consumed. Read the entire stream or use SkipEntry.");
SkipEntry();
}
if (isDisposed)
{

View File

@@ -5,16 +5,26 @@ namespace SharpCompress.Common
[Flags]
public enum ExtractOptions
{
None,
None = 0,
/// <summary>
/// overwrite target if it exists
/// </summary>
Overwrite,
Overwrite = 1 << 0,
/// <summary>
/// extract with internal directory structure
/// </summary>
ExtractFullPath,
ExtractFullPath = 1 << 1,
/// <summary>
/// preserve file time
/// </summary>
PreserveFileTime = 1 << 2,
/// <summary>
/// preserve windows file attributes
/// </summary>
PreserveAttributes = 1 << 3,
}
}

View File

@@ -16,5 +16,6 @@ namespace SharpCompress.Common
DateTime? LastAccessedTime { get; }
DateTime? LastModifiedTime { get; }
long Size { get; }
int? Attrib { get; }
}
}

View File

@@ -67,8 +67,9 @@ namespace SharpCompress.Common.SevenZip
ulong id = _currentReader.ReadNumber();
if (id > 25)
return null;
#if DEBUG
Log.WriteLine("ReadId: {0}", (BlockType)id);
#endif
return (BlockType)id;
}
@@ -197,20 +198,25 @@ namespace SharpCompress.Common.SevenZip
private void GetNextFolderItem(CFolder folder)
{
#if DEBUG
Log.WriteLine("-- GetNextFolderItem --");
Log.PushIndent();
#endif
try
{
int numCoders = ReadNum();
#if DEBUG
Log.WriteLine("NumCoders: " + numCoders);
#endif
folder.Coders = new List<CCoderInfo>(numCoders);
int numInStreams = 0;
int numOutStreams = 0;
for (int i = 0; i < numCoders; i++)
{
#if DEBUG
Log.WriteLine("-- Coder --");
Log.PushIndent();
#endif
try
{
CCoderInfo coder = new CCoderInfo();
@@ -220,11 +226,9 @@ namespace SharpCompress.Common.SevenZip
int idSize = (mainByte & 0xF);
byte[] longID = new byte[idSize];
ReadBytes(longID, 0, idSize);
Log.WriteLine("MethodId: " +
String.Join("",
Enumerable.Range(0, idSize)
.Select(x => longID[x].ToString("x2"))
.ToArray()));
#if DEBUG
Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longID[x].ToString("x2")).ToArray()));
#endif
if (idSize > 8)
throw new NotSupportedException();
ulong id = 0;
@@ -236,12 +240,15 @@ namespace SharpCompress.Common.SevenZip
{
coder.NumInStreams = ReadNum();
coder.NumOutStreams = ReadNum();
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams +
")");
#if DEBUG
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams + ")");
#endif
}
else
{
#if DEBUG
Log.WriteLine("Simple Stream (In: 1 - Out: 1)");
#endif
coder.NumInStreams = 1;
coder.NumOutStreams = 1;
}
@@ -251,8 +258,9 @@ namespace SharpCompress.Common.SevenZip
int propsSize = ReadNum();
coder.Props = new byte[propsSize];
ReadBytes(coder.Props, 0, propsSize);
Log.WriteLine("Settings: " +
String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
#if DEBUG
Log.WriteLine("Settings: " + String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
#endif
}
if ((mainByte & 0x80) != 0)
@@ -263,23 +271,31 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
int numBindPairs = numOutStreams - 1;
folder.BindPairs = new List<CBindPair>(numBindPairs);
#if DEBUG
Log.WriteLine("BindPairs: " + numBindPairs);
Log.PushIndent();
#endif
for (int i = 0; i < numBindPairs; i++)
{
CBindPair bp = new CBindPair();
bp.InIndex = ReadNum();
bp.OutIndex = ReadNum();
folder.BindPairs.Add(bp);
#if DEBUG
Log.WriteLine("#" + i + " - In: " + bp.InIndex + " - Out: " + bp.OutIndex);
#endif
}
#if DEBUG
Log.PopIndent();
#endif
if (numInStreams < numBindPairs)
throw new NotSupportedException();
@@ -292,7 +308,9 @@ namespace SharpCompress.Common.SevenZip
{
if (folder.FindBindPairForInStream(i) < 0)
{
#if DEBUG
Log.WriteLine("Single PackStream: #" + i);
#endif
folder.PackStreams.Add(i);
break;
}
@@ -303,26 +321,36 @@ namespace SharpCompress.Common.SevenZip
}
else
{
#if DEBUG
Log.WriteLine("Multiple PackStreams ...");
Log.PushIndent();
#endif
for (int i = 0; i < numPackStreams; i++)
{
var num = ReadNum();
#if DEBUG
Log.WriteLine("#" + i + " - " + num);
#endif
folder.PackStreams.Add(num);
}
#if DEBUG
Log.PopIndent();
#endif
}
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
private List<uint?> ReadHashDigests(int count)
{
#if DEBUG
Log.Write("ReadHashDigests:");
#endif
var defined = ReadOptionalBitVector(count);
var digests = new List<uint?>(count);
@@ -331,44 +359,62 @@ namespace SharpCompress.Common.SevenZip
if (defined[i])
{
uint crc = ReadUInt32();
#if DEBUG
Log.Write(" " + crc.ToString("x8"));
#endif
digests.Add(crc);
}
else
{
#if DEBUG
Log.Write(" ########");
#endif
digests.Add(null);
}
}
#if DEBUG
Log.WriteLine();
#endif
return digests;
}
private void ReadPackInfo(out long dataOffset, out List<long> packSizes, out List<uint?> packCRCs)
{
#if DEBUG
Log.WriteLine("-- ReadPackInfo --");
Log.PushIndent();
#endif
try
{
packCRCs = null;
dataOffset = checked((long)ReadNumber());
#if DEBUG
Log.WriteLine("DataOffset: " + dataOffset);
#endif
int numPackStreams = ReadNum();
#if DEBUG
Log.WriteLine("NumPackStreams: " + numPackStreams);
#endif
WaitAttribute(BlockType.Size);
packSizes = new List<long>(numPackStreams);
#if DEBUG
Log.Write("Sizes:");
#endif
for (int i = 0; i < numPackStreams; i++)
{
var size = checked((long)ReadNumber());
#if DEBUG
Log.Write(" " + size);
#endif
packSizes.Add(size);
}
#if DEBUG
Log.WriteLine();
#endif
BlockType? type;
for (; ; )
@@ -393,19 +439,25 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
private void ReadUnpackInfo(List<byte[]> dataVector, out List<CFolder> folders)
{
#if DEBUG
Log.WriteLine("-- ReadUnpackInfo --");
Log.PushIndent();
#endif
try
{
WaitAttribute(BlockType.Folder);
int numFolders = ReadNum();
#if DEBUG
Log.WriteLine("NumFolders: {0}", numFolders);
#endif
using (CStreamSwitch streamSwitch = new CStreamSwitch())
{
@@ -424,20 +476,27 @@ namespace SharpCompress.Common.SevenZip
}
WaitAttribute(BlockType.CodersUnpackSize);
#if DEBUG
Log.WriteLine("UnpackSizes:");
#endif
for (int i = 0; i < numFolders; i++)
{
CFolder folder = folders[i];
#if DEBUG
Log.Write(" #" + i + ":");
#endif
int numOutStreams = folder.GetNumOutStreams();
for (int j = 0; j < numOutStreams; j++)
{
long size = checked((long)ReadNumber());
#if DEBUG
Log.Write(" " + size);
#endif
folder.UnpackSizes.Add(size);
}
#if DEBUG
Log.WriteLine();
#endif
}
for (; ; )
@@ -459,15 +518,19 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
private void ReadSubStreamsInfo(List<CFolder> folders, out List<int> numUnpackStreamsInFolders,
out List<long> unpackSizes, out List<uint?> digests)
{
#if DEBUG
Log.WriteLine("-- ReadSubStreamsInfo --");
Log.PushIndent();
#endif
try
{
numUnpackStreamsInFolders = null;
@@ -479,14 +542,20 @@ namespace SharpCompress.Common.SevenZip
if (type == BlockType.NumUnpackStream)
{
numUnpackStreamsInFolders = new List<int>(folders.Count);
#if DEBUG
Log.Write("NumUnpackStreams:");
#endif
for (int i = 0; i < folders.Count; i++)
{
var num = ReadNum();
#if DEBUG
Log.Write(" " + num);
#endif
numUnpackStreamsInFolders.Add(num);
}
#if DEBUG
Log.WriteLine();
#endif
continue;
}
if (type == BlockType.CRC || type == BlockType.Size)
@@ -511,21 +580,26 @@ namespace SharpCompress.Common.SevenZip
int numSubstreams = numUnpackStreamsInFolders[i];
if (numSubstreams == 0)
continue;
#if DEBUG
Log.Write("#{0} StreamSizes:", i);
#endif
long sum = 0;
for (int j = 1; j < numSubstreams; j++)
{
if (type == BlockType.Size)
{
long size = checked((long)ReadNumber());
#if DEBUG
Log.Write(" " + size);
#endif
unpackSizes.Add(size);
sum += size;
}
}
unpackSizes.Add(folders[i].GetUnpackSize() - sum);
#if DEBUG
Log.WriteLine(" - rest: " + unpackSizes.Last());
#endif
}
if (type == BlockType.Size)
type = ReadId();
@@ -589,7 +663,9 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
@@ -603,8 +679,10 @@ namespace SharpCompress.Common.SevenZip
out List<long> unpackSizes,
out List<uint?> digests)
{
#if DEBUG
Log.WriteLine("-- ReadStreamsInfo --");
Log.PushIndent();
#endif
try
{
dataOffset = long.MinValue;
@@ -637,14 +715,18 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
private List<byte[]> ReadAndDecodePackedStreams(long baseOffset, IPasswordProvider pass)
{
#if DEBUG
Log.WriteLine("-- ReadAndDecodePackedStreams --");
Log.PushIndent();
#endif
try
{
long dataStartPos;
@@ -697,14 +779,18 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
private void ReadHeader(ArchiveDatabase db, IPasswordProvider getTextPassword)
{
#if DEBUG
Log.WriteLine("-- ReadHeader --");
Log.PushIndent();
#endif
try
{
BlockType? type = ReadId();
@@ -762,7 +848,9 @@ namespace SharpCompress.Common.SevenZip
throw new InvalidOperationException();
int numFiles = ReadNum();
#if DEBUG
Log.WriteLine("NumFiles: " + numFiles);
#endif
db.Files = new List<CFileItem>(numFiles);
for (int i = 0; i < numFiles; i++)
db.Files.Add(new CFileItem());
@@ -786,112 +874,147 @@ namespace SharpCompress.Common.SevenZip
using (var streamSwitch = new CStreamSwitch())
{
streamSwitch.Set(this, dataVector);
#if DEBUG
Log.Write("FileNames:");
#endif
for (int i = 0; i < db.Files.Count; i++)
{
db.Files[i].Name = _currentReader.ReadString();
#if DEBUG
Log.Write(" " + db.Files[i].Name);
#endif
}
#if DEBUG
Log.WriteLine();
#endif
}
break;
case BlockType.WinAttributes:
#if DEBUG
Log.Write("WinAttributes:");
#endif
ReadAttributeVector(dataVector, numFiles, delegate(int i, uint? attr)
{
db.Files[i].Attrib = attr;
Log.Write(" " +
(attr.HasValue
? attr.Value.ToString("x8")
: "n/a"));
#if DEBUG
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));
#endif
});
#if DEBUG
Log.WriteLine();
#endif
break;
case BlockType.EmptyStream:
emptyStreamVector = ReadBitVector(numFiles);
#if DEBUG
Log.Write("EmptyStream: ");
#endif
for (int i = 0; i < emptyStreamVector.Length; i++)
{
if (emptyStreamVector[i])
{
#if DEBUG
Log.Write("x");
#endif
numEmptyStreams++;
}
else
{
#if DEBUG
Log.Write(".");
#endif
}
}
#if DEBUG
Log.WriteLine();
#endif
emptyFileVector = new BitVector(numEmptyStreams);
antiFileVector = new BitVector(numEmptyStreams);
break;
case BlockType.EmptyFile:
emptyFileVector = ReadBitVector(numEmptyStreams);
#if DEBUG
Log.Write("EmptyFile: ");
for (int i = 0; i < numEmptyStreams; i++)
Log.Write(emptyFileVector[i] ? "x" : ".");
Log.WriteLine();
#endif
break;
case BlockType.Anti:
antiFileVector = ReadBitVector(numEmptyStreams);
#if DEBUG
Log.Write("Anti: ");
for (int i = 0; i < numEmptyStreams; i++)
Log.Write(antiFileVector[i] ? "x" : ".");
Log.WriteLine();
#endif
break;
case BlockType.StartPos:
#if DEBUG
Log.Write("StartPos:");
#endif
ReadNumberVector(dataVector, numFiles, delegate(int i, long? startPos)
{
db.Files[i].StartPos = startPos;
Log.Write(" " +
(startPos.HasValue
? startPos.Value.ToString()
: "n/a"));
#if DEBUG
Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a"));
#endif
});
#if DEBUG
Log.WriteLine();
#endif
break;
case BlockType.CTime:
#if DEBUG
Log.Write("CTime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].CTime = time;
Log.Write(" " +
(time.HasValue
? time.Value.ToString()
: "n/a"));
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
#if DEBUG
Log.WriteLine();
#endif
break;
case BlockType.ATime:
#if DEBUG
Log.Write("ATime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].ATime = time;
Log.Write(" " +
(time.HasValue
? time.Value.ToString()
: "n/a"));
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
#if DEBUG
Log.WriteLine();
#endif
break;
case BlockType.MTime:
#if DEBUG
Log.Write("MTime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].MTime = time;
Log.Write(" " +
(time.HasValue
? time.Value.ToString()
: "n/a"));
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
#if DEBUG
Log.WriteLine();
#endif
break;
case BlockType.Dummy:
#if DEBUG
Log.Write("Dummy: " + size);
#endif
for (long j = 0; j < size; j++)
if (ReadByte() != 0)
throw new InvalidOperationException();
@@ -933,7 +1056,9 @@ namespace SharpCompress.Common.SevenZip
}
finally
{
#if DEBUG
Log.PopIndent();
#endif
}
}
@@ -1156,7 +1281,9 @@ namespace SharpCompress.Common.SevenZip
//string filename = @"D:\_testdump\" + _db.Files[index].Name;
//Directory.CreateDirectory(Path.GetDirectoryName(filename));
//_stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Delete);
#if DEBUG
Log.WriteLine(_db.Files[index].Name);
#endif
if (_db.Files[index].CrcDefined)
_stream = new CrcCheckStream(_db.Files[index].Crc.Value);
else

View File

@@ -16,7 +16,9 @@ namespace SharpCompress.Common.SevenZip
if (_active)
{
_active = false;
#if DEBUG
Log.WriteLine("[end of switch]");
#endif
}
if (_needRemove)
@@ -47,7 +49,9 @@ namespace SharpCompress.Common.SevenZip
if (dataIndex < 0 || dataIndex >= dataVector.Count)
throw new InvalidOperationException();
#if DEBUG
Log.WriteLine("[switch to stream {0}]", dataIndex);
#endif
_archive = archive;
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
_needRemove = true;
@@ -55,7 +59,9 @@ namespace SharpCompress.Common.SevenZip
}
else
{
#if DEBUG
Log.WriteLine("[inline data]");
#endif
}
}
}

View File

@@ -78,7 +78,9 @@ namespace SharpCompress.Common.SevenZip
throw new EndOfStreamException();
_offset += (int) size;
#if DEBUG
Log.WriteLine("SkipData {0}", size);
#endif
}
public void SkipData()

View File

@@ -72,6 +72,11 @@ namespace SharpCompress.Common.SevenZip
get { return false; }
}
public override int? Attrib
{
get { return (int) FilePart.Header.Attrib; }
}
internal override IEnumerable<FilePart> Parts
{
get { return FilePart.AsEnumerable<FilePart>(); }

View File

@@ -8,7 +8,7 @@ namespace SharpCompress.Common.Zip
{
internal class SeekableZipHeaderFactory : ZipHeaderFactory
{
private const int MAX_ITERATIONS_FOR_DIRECTORY_HEADER = 1000;
private const int MAX_ITERATIONS_FOR_DIRECTORY_HEADER = 4096;
internal SeekableZipHeaderFactory(string password)
: base(StreamingMode.Seekable, password)

View File

@@ -45,18 +45,17 @@ namespace SharpCompress.Common.Zip
lastEntryHeader = null;
uint headerBytes = reader.ReadUInt32();
header = ReadHeader(headerBytes, reader);
//entry could be zero bytes so we need to know that.
if (header.ZipHeaderType == ZipHeaderType.LocalEntry)
{
bool isRecording = rewindableStream.IsRecording;
if (!isRecording)
{
rewindableStream.StartRecording();
if (header != null) {
// entry could be zero bytes so we need to know that.
if(header.ZipHeaderType == ZipHeaderType.LocalEntry) {
bool isRecording = rewindableStream.IsRecording;
if (!isRecording) {
rewindableStream.StartRecording();
}
uint nextHeaderBytes = reader.ReadUInt32();
header.HasData = !IsHeader(nextHeaderBytes);
rewindableStream.Rewind(!isRecording);
}
uint nextHeaderBytes = reader.ReadUInt32();
header.HasData = !IsHeader(nextHeaderBytes);
rewindableStream.Rewind(!isRecording);
}
yield return header;
}

View File

@@ -87,7 +87,7 @@ namespace SharpCompress.Common.Zip
return entry;
}
default:
throw new NotSupportedException("Unknown header: " + headerBytes);
return null;
}
}

View File

@@ -677,10 +677,10 @@ namespace SharpCompress.Compressor.Deflate
{
if (bi_valid > (int) Buf_size - len)
{
//int val = value;
// bi_buf |= (val << bi_valid);
int x = (value << bi_valid) & 0xffff;
bi_buf = (short)((int)bi_buf | x);
bi_buf |= (short) ((value << bi_valid) & 0xffff);
//put_short(bi_buf);
pending[pendingCount++] = (byte) bi_buf;
pending[pendingCount++] = (byte) (bi_buf >> 8);
@@ -691,8 +691,10 @@ namespace SharpCompress.Compressor.Deflate
}
else
{
// bi_buf |= (value) << bi_valid;
bi_buf |= (short) ((value << bi_valid) & 0xffff);
// bi_buf |= (val << bi_valid);
int x = (value << bi_valid) & 0xffff;
bi_buf = (short)((int)bi_buf | x);
bi_valid += len;
}
}

View File

@@ -79,33 +79,5 @@ namespace SharpCompress.Compressor.LZMA
return crc;
}
#if !PORTABLE && !NETFX_CORE
public static unsafe uint Update(uint crc, byte* buffer, int length)
{
while (length > 0 && ((int) buffer & 3) != 0)
{
crc = Update(crc, *buffer);
buffer++;
length--;
}
while (length >= 4)
{
crc = Update(crc, *(uint*) buffer);
buffer += 4;
length -= 4;
}
while (length > 0)
{
crc = Update(crc, *buffer);
length--;
}
return crc;
}
#endif
}
}

View File

@@ -67,12 +67,32 @@ namespace SharpCompress.Reader
#endregion
public bool Cancelled { get; private set; }
/// <summary>
/// Indicates that the remaining entries are not required.
/// On dispose of an EntryStream, the stream will not skip to the end of the entry.
/// An attempt to move to the next entry will throw an exception, as the compressed stream is not positioned at an entry boundary.
/// </summary>
public void Cancel()
{
if (!completed)
{
Cancelled = true;
}
}
public bool MoveToNextEntry()
{
if (completed)
{
return false;
}
if (Cancelled)
{
throw new InvalidOperationException("Reader has been cancelled.");
}
if (entriesForCurrentReadStream == null)
{
return LoadStreamForReading(RequestInitialStream());
@@ -197,9 +217,17 @@ namespace SharpCompress.Reader
return stream;
}
/// <summary>
/// Retains a reference to the entry stream, so we can check whether it completed later.
/// </summary>
protected EntryStream CreateEntryStream(Stream decompressed)
{
return new EntryStream(this, decompressed);
}
protected virtual EntryStream GetEntryStream()
{
return new EntryStream(Entry.Parts.First().GetCompressedStream());
return CreateEntryStream(Entry.Parts.First().GetCompressedStream());
}
#endregion

View File

@@ -22,6 +22,9 @@ namespace SharpCompress.Reader
/// <param name="writableStream"></param>
void WriteEntryTo(Stream writableStream);
bool Cancelled { get; }
void Cancel();
/// <summary>
/// Moves to the next entry by reading more data from the underlying stream. This skips if data has not been read.
/// </summary>

View File

@@ -73,7 +73,7 @@ namespace SharpCompress.Reader.Rar
protected override EntryStream GetEntryStream()
{
return new EntryStream(new RarStream(pack, Entry.FileHeader,
return CreateEntryStream(new RarStream(pack, Entry.FileHeader,
new MultiVolumeReadOnlyStream(
CreateFilePartEnumerableForCurrentEntry().Cast<RarFilePart>(), this)));
}

View File

@@ -1,394 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SharpCompress</RootNamespace>
<AssemblyName>SharpCompress</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<BaseIntermediateOutputPath>obj\LinqBridge\</BaseIntermediateOutputPath>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\sharpcompress\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\NET2\</OutputPath>
<DefineConstants>TRACE;DEBUG;DISABLE_TRACE;NET2</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<NoWarn>1591</NoWarn>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\NET2\</OutputPath>
<DefineConstants>TRACE;NET2</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>
</DocumentationFile>
<NoWarn>1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>SharpCompress.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="LinqBridge">
<HintPath>..\packages\LinqBridge.1.3.0\lib\net20\LinqBridge.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Archive\IWritableArchive.cs" />
<Compile Include="Archive\IWritableArchive.Extensions.cs" />
<Compile Include="Archive\IWritableArchiveEntry.cs" />
<Compile Include="Archive\Rar\FileInfoRarFilePart.cs" />
<Compile Include="Common\ArchiveEncoding.cs" />
<Compile Include="Archive\AbstractWritableArchive.cs" />
<Compile Include="Archive\AbstractArchive.cs" />
<Compile Include="Archive\ArchiveFactory.cs" />
<Compile Include="Archive\GZip\GZipWritableArchiveEntry.cs" />
<Compile Include="Archive\IArchive.Extensions.cs" />
<Compile Include="Archive\GZip\GZipArchive.cs" />
<Compile Include="Archive\GZip\GZipArchiveEntry.cs" />
<Compile Include="Archive\IArchiveEntry.cs" />
<Compile Include="Archive\Rar\RarArchiveEntryFactory.cs" />
<Compile Include="Archive\IArchive.cs" />
<Compile Include="Archive\Rar\StreamRarArchiveVolume.cs" />
<Compile Include="Archive\SevenZip\SevenZipArchive.cs" />
<Compile Include="Archive\SevenZip\SevenZipArchiveEntry.cs" />
<Compile Include="Archive\Tar\TarArchive.cs" />
<Compile Include="Archive\Tar\TarArchiveEntry.cs" />
<Compile Include="Archive\Tar\TarWritableArchiveEntry.cs" />
<Compile Include="Archive\Zip\ZipWritableArchiveEntry.cs" />
<Compile Include="Archive\Zip\ZipArchive.cs" />
<Compile Include="Archive\Zip\ZipArchiveEntry.cs" />
<Compile Include="Common\ArchiveException.cs" />
<Compile Include="Common\ArchiveExtractionEventArgs.cs" />
<Compile Include="Common\CompressedBytesReadEventArgs.cs" />
<Compile Include="Common\CompressionInfo.cs" />
<Compile Include="Common\CompressionType.cs" />
<Compile Include="Common\FilePartExtractionBeginEventArgs.cs" />
<Compile Include="Archive\IArchiveExtractionListener.cs" />
<Compile Include="Common\IncompleteArchiveException.cs" />
<Compile Include="Common\MultiVolumeExtractionException.cs" />
<Compile Include="Common\PasswordProtectedException.cs" />
<Compile Include="Common\CryptographicException.cs" />
<Compile Include="Common\FlagUtility.cs" />
<Compile Include="Common\GZip\GZipEntry.cs" />
<Compile Include="Common\GZip\GZipFilePart.cs" />
<Compile Include="Common\GZip\GZipVolume.cs" />
<Compile Include="Common\ExtractOptions.cs" />
<Compile Include="Common\FilePart.cs" />
<Compile Include="Common\Entry.cs" />
<Compile Include="Common\IEntry.cs" />
<Compile Include="Common\IVolume.cs" />
<Compile Include="Common\Rar\RarCryptoWrapper.cs" />
<Compile Include="Common\Rar\RarRijndael.cs" />
<Compile Include="Common\ReaderExtractionEventArgs.cs" />
<Compile Include="Common\SevenZip\CBindPair.cs" />
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
<Compile Include="Common\SevenZip\CFileItem.cs" />
<Compile Include="Common\SevenZip\CFolder.cs" />
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
<Compile Include="Common\SevenZip\DataReader.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
<Compile Include="Common\Tar\TarReadOnlySubStream.cs" />
<Compile Include="Common\Tar\TarVolume.cs" />
<Compile Include="Common\Tar\TarEntry.cs" />
<Compile Include="Common\Tar\TarFilePart.cs" />
<Compile Include="Common\Tar\TarHeaderFactory.cs" />
<Compile Include="Common\Zip\Headers\HeaderFlags.cs" />
<Compile Include="Common\Zip\Headers\IgnoreHeader.cs" />
<Compile Include="Common\Zip\Headers\LocalEntryHeaderExtraFactory.cs" />
<Compile Include="Common\Zip\Headers\SplitHeader.cs" />
<Compile Include="Common\Zip\Headers\ZipFileEntry.cs" />
<Compile Include="Common\Zip\Headers\ZipHeaderType.cs" />
<Compile Include="Common\Zip\SeekableZipFilePart.cs" />
<Compile Include="Common\Zip\SeekableZipHeaderFactory.cs" />
<Compile Include="Common\Zip\StreamingZipFilePart.cs" />
<Compile Include="Common\Zip\StreamingZipHeaderFactory.cs" />
<Compile Include="Common\Zip\WinzipAesCryptoStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Common\Zip\WinzipAesEncryptionData.cs" />
<Compile Include="Common\Zip\WinzipAesKeySize.cs" />
<Compile Include="Common\Zip\ZipVolume.cs" />
<Compile Include="Compressor\BZip2\BZip2Constants.cs" />
<Compile Include="Compressor\BZip2\BZip2Stream.cs" />
<Compile Include="Compressor\BZip2\CBZip2InputStream.cs" />
<Compile Include="Compressor\BZip2\CBZip2OutputStream.cs" />
<Compile Include="Compressor\BZip2\CRC.cs" />
<Compile Include="Compressor\CompressionMode.cs" />
<Compile Include="Compressor\Deflate\FlushType.cs" />
<Compile Include="Common\Zip\PkwareTraditionalCryptoStream.cs" />
<Compile Include="Common\Zip\PkwareTraditionalEncryptionData.cs" />
<Compile Include="Compressor\Deflate\GZipStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
<Compile Include="Compressor\Filters\BCJFilter.cs" />
<Compile Include="Compressor\Filters\Filter.cs" />
<Compile Include="Compressor\LZMA\BitVector.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\LZ\CRC.cs" />
<Compile Include="Compressor\LZMA\CRC.cs" />
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
<Compile Include="Common\SevenZip\CMethodId.cs" />
<Compile Include="Compressor\LZMA\AesDecoderStream.cs" />
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
<Compile Include="Compressor\LZMA\Registry.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\Log.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\LzmaBase.cs" />
<Compile Include="Compressor\LZMA\LzmaDecoder.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoder.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
<Compile Include="Compressor\LZMA\LZ\LzInWindow.cs" />
<Compile Include="Compressor\LZMA\LZ\LzOutWindow.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\Utils.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\PPMd\H\FreqData.cs" />
<Compile Include="Compressor\PPMd\H\ModelPPM.cs" />
<Compile Include="Compressor\PPMd\H\Pointer.cs" />
<Compile Include="Compressor\PPMd\H\PPMContext.cs" />
<Compile Include="Compressor\PPMd\H\RangeCoder.cs" />
<Compile Include="Compressor\PPMd\H\RarMemBlock.cs" />
<Compile Include="Compressor\PPMd\H\RarNode.cs" />
<Compile Include="Compressor\PPMd\H\SEE2Context.cs" />
<Compile Include="Compressor\PPMd\H\State.cs" />
<Compile Include="Compressor\PPMd\H\StateRef.cs" />
<Compile Include="Compressor\PPMd\H\SubAllocator.cs" />
<Compile Include="Compressor\PPMd\I1\Allocator.cs" />
<Compile Include="Compressor\PPMd\I1\Coder.cs" />
<Compile Include="Compressor\PPMd\I1\MemoryNode.cs" />
<Compile Include="Compressor\PPMd\I1\Model.cs" />
<Compile Include="Compressor\PPMd\I1\ModelRestorationMethod.cs" />
<Compile Include="Compressor\PPMd\I1\Pointer.cs" />
<Compile Include="Compressor\PPMd\I1\PpmContext.cs" />
<Compile Include="Compressor\PPMd\I1\PpmState.cs" />
<Compile Include="Compressor\PPMd\I1\See2Context.cs" />
<Compile Include="Compressor\PPMd\PpmdProperties.cs" />
<Compile Include="Compressor\PPMd\PpmdStream.cs" />
<Compile Include="Compressor\Rar\RarStream.cs" />
<Compile Include="EnumExtensions.cs" />
<Compile Include="IO\CountingWritableSubStream.cs" />
<Compile Include="Common\EntryStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="IO\ListeningStream.cs" />
<Compile Include="IO\NonDisposingStream.cs" />
<Compile Include="Common\Rar\RarCryptoBinaryReader.cs" />
<Compile Include="IO\RewindableStream.cs" />
<Compile Include="Reader\GZip\GZipReader.cs" />
<Compile Include="Reader\IReaderExtractionListener.cs" />
<Compile Include="Reader\ReaderFactory.cs" />
<Compile Include="Reader\AbstractReader.cs" />
<Compile Include="Common\Volume.cs" />
<Compile Include="Compressor\Deflate\CRC32.cs" />
<Compile Include="Compressor\Deflate\DeflateManager.cs" />
<Compile Include="Compressor\Deflate\DeflateStream.cs" />
<Compile Include="Compressor\Deflate\Inflate.cs" />
<Compile Include="Compressor\Deflate\InfTree.cs" />
<Compile Include="Compressor\Deflate\Tree.cs" />
<Compile Include="Compressor\Deflate\Zlib.cs" />
<Compile Include="Compressor\Deflate\ZlibBaseStream.cs" />
<Compile Include="Compressor\Deflate\ZlibCodec.cs" />
<Compile Include="Compressor\Deflate\ZlibConstants.cs" />
<Compile Include="Compressor\Deflate\ZlibStream.cs" />
<Compile Include="Common\Rar\Headers\FileNameDecoder.cs" />
<Compile Include="Common\InvalidFormatException.cs" />
<Compile Include="IO\ReadOnlySubStream.cs" />
<Compile Include="IO\StreamingMode.cs" />
<Compile Include="Common\IExtractionListener.cs" />
<Compile Include="Common\MultipartStreamRequiredException.cs" />
<Compile Include="LazyReadOnlyCollection.cs" />
<Compile Include="Archive\Rar\RarArchive.Extensions.cs" />
<Compile Include="Archive\IArchiveEntry.Extensions.cs" />
<Compile Include="Archive\Rar\RarArchiveEntry.cs" />
<Compile Include="Common\ExtractionException.cs" />
<Compile Include="Common\Rar\RarEntry.cs" />
<Compile Include="Common\Options.cs" />
<Compile Include="Reader\IReader.cs" />
<Compile Include="Reader\Rar\MultiVolumeRarReader.cs" />
<Compile Include="Reader\Rar\RarReader.cs" />
<Compile Include="Reader\IReader.Extensions.cs" />
<Compile Include="Reader\Rar\RarReaderEntry.cs" />
<Compile Include="Archive\Rar\SeekableFilePart.cs" />
<Compile Include="Reader\Rar\SingleVolumeRarReader.cs" />
<Compile Include="Common\ArchiveType.cs" />
<Compile Include="Reader\Tar\TarReader.cs" />
<Compile Include="ReadOnlyCollection.cs" />
<Compile Include="VersionInfo.cs" />
<Compile Include="Archive\Rar\FileInfoRarArchiveVolume.cs" />
<Compile Include="Common\Rar\RarFilePart.cs" />
<Compile Include="Common\Rar\Headers\AVHeader.cs" />
<Compile Include="Common\Rar\Headers\CommentHeader.cs" />
<Compile Include="Common\Rar\Headers\EndArchiveHeader.cs" />
<Compile Include="Common\Rar\Headers\SignHeader.cs" />
<Compile Include="Common\Rar\RarVolume.cs" />
<Compile Include="Compressor\Rar\UnpackUtility.cs" />
<Compile Include="Archive\Rar\RarArchive.cs" />
<Compile Include="Compressor\Rar\MultiVolumeReadOnlyStream.cs" />
<Compile Include="Compressor\Rar\RarCRC.cs" />
<Compile Include="Common\Rar\Headers\FileHeader.cs" />
<Compile Include="Common\Rar\Headers\ArchiveHeader.cs" />
<Compile Include="Common\Rar\Headers\RarHeader.cs" />
<Compile Include="IO\MarkingBinaryReader.cs" />
<Compile Include="Common\Rar\Headers\NewSubHeader.cs" />
<Compile Include="Common\Rar\Headers\ProtectHeader.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Common\Rar\Headers\RarHeaderFactory.cs" />
<Compile Include="Common\Rar\Headers\Flags.cs" />
<Compile Include="Compressor\Rar\Decode\AudioVariables.cs" />
<Compile Include="Compressor\Rar\Decode\BitDecode.cs" />
<Compile Include="Compressor\Rar\Decode\CodeType.cs" />
<Compile Include="Compressor\Rar\Decode\Compress.cs" />
<Compile Include="Compressor\Rar\Decode\Decode.cs" />
<Compile Include="Compressor\Rar\Decode\DistDecode.cs" />
<Compile Include="Compressor\Rar\Decode\FilterType.cs" />
<Compile Include="Compressor\Rar\Decode\LitDecode.cs" />
<Compile Include="Compressor\Rar\Decode\LowDistDecode.cs" />
<Compile Include="Compressor\Rar\Decode\MultDecode.cs" />
<Compile Include="Compressor\Rar\Decode\RepDecode.cs" />
<Compile Include="Compressor\Rar\PPM\BlockTypes.cs" />
<Compile Include="Compressor\Rar\Unpack.cs" />
<Compile Include="Compressor\Rar\Unpack15.cs" />
<Compile Include="Compressor\Rar\Unpack20.cs" />
<Compile Include="Compressor\Rar\UnpackFilter.cs" />
<Compile Include="Compressor\Rar\VM\BitInput.cs" />
<Compile Include="Compressor\Rar\VM\RarVM.cs" />
<Compile Include="Compressor\Rar\VM\VMCmdFlags.cs" />
<Compile Include="Compressor\Rar\VM\VMCommands.cs" />
<Compile Include="Compressor\Rar\VM\VMFlags.cs" />
<Compile Include="Compressor\Rar\VM\VMOpType.cs" />
<Compile Include="Compressor\Rar\VM\VMPreparedCommand.cs" />
<Compile Include="Compressor\Rar\VM\VMPreparedOperand.cs" />
<Compile Include="Compressor\Rar\VM\VMPreparedProgram.cs" />
<Compile Include="Compressor\Rar\VM\VMStandardFilters.cs" />
<Compile Include="Compressor\Rar\VM\VMStandardFilterSignature.cs" />
<Compile Include="Utility.cs" />
<Compile Include="Common\Rar\Headers\MarkHeader.cs" />
<Compile Include="Archive\Rar\RarArchiveVolumeFactory.cs" />
<Compile Include="Reader\Rar\NonSeekableStreamFilePart.cs" />
<Compile Include="Reader\Rar\RarReaderVolume.cs" />
<Compile Include="Common\Zip\ZipCompressionMethod.cs" />
<Compile Include="Common\Zip\Headers\DirectoryEndHeader.cs" />
<Compile Include="Common\Zip\Headers\DirectoryEntryHeader.cs" />
<Compile Include="Common\Zip\Headers\LocalEntryHeader.cs" />
<Compile Include="Common\Zip\ZipFilePart.cs" />
<Compile Include="Common\Zip\Headers\ZipHeader.cs" />
<Compile Include="Common\Zip\ZipHeaderFactory.cs" />
<Compile Include="Reader\Zip\ZipReader.cs" />
<Compile Include="Common\Zip\ZipEntry.cs" />
<Compile Include="Writer\AbstractWriter.cs" />
<Compile Include="Writer\GZip\GZipWriter.cs" />
<Compile Include="Writer\IWriter.Extensions.cs" />
<Compile Include="Writer\IWriter.cs" />
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="SharpCompress.pfx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -321,6 +321,7 @@
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -371,6 +371,7 @@
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -359,6 +359,7 @@
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -306,6 +306,7 @@
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -359,6 +359,7 @@
<Compile Include="Writer\Tar\TarWriter.cs" />
<Compile Include="Writer\WriterFactory.cs" />
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
<Compile Include="Writer\Zip\ZipWriter.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -199,21 +199,15 @@ namespace SharpCompress
/// </param>
/// <param name="value">the value to write
/// </param>
#if PORTABLE || NETFX_CORE
public static void WriteLittleEndian(byte[] array, int pos, short value)
{
byte[] newBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
Array.Reverse(newBytes);
Array.Copy(newBytes, 0, array, pos, newBytes.Length);
}
#else
public static unsafe void WriteLittleEndian(byte[] array, int pos, short value)
{
fixed (byte* numRef = &(array[pos]))
{
*((short*)numRef) = value;
}
}
#endif
/// <summary> Increment a short value at the specified position by the specified amount
/// (little endian).
@@ -241,21 +235,15 @@ namespace SharpCompress
/// </param>
/// <param name="value">the value to write
/// </param>
#if PORTABLE || NETFX_CORE
public static void WriteLittleEndian(byte[] array, int pos, int value)
{
byte[] newBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
Array.Reverse(newBytes);
Array.Copy(newBytes, 0, array, pos, newBytes.Length);
}
#else
public static unsafe void WriteLittleEndian(byte[] array, int pos, int value)
{
fixed (byte* numRef = &(array[pos]))
{
*((int*)numRef) = value;
}
}
#endif
public static void Initialize<T>(this T[] array, Func<T> func)
{

View File

@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © Adam Hathcock")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.10.3.0")]
[assembly: AssemblyFileVersion("0.10.3.0")]
[assembly: AssemblyVersion("0.11.2.0")]
[assembly: AssemblyFileVersion("0.11.2.0")]

View File

@@ -0,0 +1,47 @@
using SharpCompress.Common;
using SharpCompress.Common.Zip;
using SharpCompress.Compressor.Deflate;
namespace SharpCompress.Writer.Zip
{
internal class ZipCompressionInfo
{
internal CompressionLevel DeflateCompressionLevel { get; private set; }
internal ZipCompressionMethod Compression { get; private set; }
public ZipCompressionInfo(CompressionInfo compressionInfo)
{
switch (compressionInfo.Type)
{
case CompressionType.None:
{
this.Compression = ZipCompressionMethod.None;
}
break;
case CompressionType.Deflate:
{
this.DeflateCompressionLevel = compressionInfo.DeflateCompressionLevel;
this.Compression = ZipCompressionMethod.Deflate;
}
break;
case CompressionType.BZip2:
{
this.Compression = ZipCompressionMethod.BZip2;
}
break;
case CompressionType.LZMA:
{
this.Compression = ZipCompressionMethod.LZMA;
}
break;
case CompressionType.PPMd:
{
this.Compression = ZipCompressionMethod.PPMd;
}
break;
default:
throw new InvalidFormatException("Invalid compression method: " + compressionInfo.Type);
}
}
}
}

View File

@@ -17,52 +17,18 @@ namespace SharpCompress.Writer.Zip
{
public class ZipWriter : AbstractWriter
{
private readonly ZipCompressionMethod compression;
private readonly CompressionLevel deflateCompressionLevel;
private readonly ZipCompressionInfo zipCompressionInfo;
private readonly PpmdProperties ppmdProperties = new PpmdProperties(); // Caching properties to speed up PPMd
private readonly List<ZipCentralDirectoryEntry> entries = new List<ZipCentralDirectoryEntry>();
private readonly string zipComment;
private long streamPosition;
private readonly PpmdProperties ppmdProperties; // Caching properties to speed up PPMd.
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment)
: base(ArchiveType.Zip)
{
this.zipComment = zipComment ?? string.Empty;
switch (compressionInfo.Type)
{
case CompressionType.None:
{
compression = ZipCompressionMethod.None;
}
break;
case CompressionType.Deflate:
{
compression = ZipCompressionMethod.Deflate;
deflateCompressionLevel = compressionInfo.DeflateCompressionLevel;
}
break;
case CompressionType.BZip2:
{
compression = ZipCompressionMethod.BZip2;
}
break;
case CompressionType.LZMA:
{
compression = ZipCompressionMethod.LZMA;
}
break;
case CompressionType.PPMd:
{
ppmdProperties = new PpmdProperties();
compression = ZipCompressionMethod.PPMd;
}
break;
default:
throw new InvalidFormatException("Invalid compression method: " + compressionInfo.Type);
}
this.zipCompressionInfo = new ZipCompressionInfo(compressionInfo);
InitalizeStream(destination, false);
}
@@ -73,7 +39,7 @@ namespace SharpCompress.Writer.Zip
uint size = 0;
foreach (ZipCentralDirectoryEntry entry in entries)
{
size += entry.Write(OutputStream, compression);
size += entry.Write(OutputStream, zipCompressionInfo.Compression);
}
WriteEndRecord(size);
}
@@ -85,15 +51,15 @@ namespace SharpCompress.Writer.Zip
Write(entryPath, source, modificationTime, null);
}
public void Write(string entryPath, Stream source, DateTime? modificationTime, string comment)
public void Write(string entryPath, Stream source, DateTime? modificationTime, string comment, CompressionInfo compressionInfo = null)
{
using (Stream output = WriteToStream(entryPath, modificationTime, comment))
using (Stream output = WriteToStream(entryPath, modificationTime, comment, compressionInfo))
{
source.TransferTo(output);
}
}
public Stream WriteToStream(string entryPath, DateTime? modificationTime, string comment)
public Stream WriteToStream(string entryPath, DateTime? modificationTime, string comment, CompressionInfo compressionInfo = null)
{
entryPath = NormalizeFilename(entryPath);
modificationTime = modificationTime ?? DateTime.Now;
@@ -105,7 +71,8 @@ namespace SharpCompress.Writer.Zip
ModificationTime = modificationTime,
HeaderOffset = (uint) streamPosition,
};
var headersize = (uint) WriteHeader(entryPath, modificationTime);
var headersize = (uint)WriteHeader(entryPath, modificationTime, compressionInfo);
streamPosition += headersize;
return new ZipWritingStream(this, OutputStream, entry);
}
@@ -121,23 +88,31 @@ namespace SharpCompress.Writer.Zip
return filename.Trim('/');
}
private int WriteHeader(string filename, DateTime? modificationTime)
private int WriteHeader(string filename, DateTime? modificationTime, CompressionInfo compressionInfo = null)
{
var explicitZipCompressionInfo = compressionInfo != null ? new ZipCompressionInfo(compressionInfo) : this.zipCompressionInfo;
byte[] encodedFilename = ArchiveEncoding.Default.GetBytes(filename);
OutputStream.Write(BitConverter.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version
if (explicitZipCompressionInfo.Compression == ZipCompressionMethod.Deflate)
{
OutputStream.Write(new byte[] {20, 0}, 0, 2); //older version which is more compatible
}
else
{
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version says we used PPMd or LZMA
}
HeaderFlags flags = ArchiveEncoding.Default == Encoding.UTF8 ? HeaderFlags.UTF8 : (HeaderFlags)0;
if (!OutputStream.CanSeek)
{
flags |= HeaderFlags.UsePostDataDescriptor;
if (compression == ZipCompressionMethod.LZMA)
if (explicitZipCompressionInfo.Compression == ZipCompressionMethod.LZMA)
{
flags |= HeaderFlags.Bit1; // eos marker
}
}
OutputStream.Write(BitConverter.GetBytes((ushort) flags), 0, 2);
OutputStream.Write(BitConverter.GetBytes((ushort) compression), 0, 2); // zipping method
OutputStream.Write(BitConverter.GetBytes((ushort)explicitZipCompressionInfo.Compression), 0, 2); // zipping method
OutputStream.Write(BitConverter.GetBytes(modificationTime.DateTimeToDosTime()), 0, 4);
// zipping date and time
OutputStream.Write(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 12);
@@ -220,7 +195,7 @@ namespace SharpCompress.Writer.Zip
{
counting = new CountingWritableSubStream(writeStream);
Stream output = counting;
switch (writer.compression)
switch (writer.zipCompressionInfo.Compression)
{
case ZipCompressionMethod.None:
{
@@ -228,7 +203,7 @@ namespace SharpCompress.Writer.Zip
}
case ZipCompressionMethod.Deflate:
{
return new DeflateStream(counting, CompressionMode.Compress, writer.deflateCompressionLevel,
return new DeflateStream(counting, CompressionMode.Compress, writer.zipCompressionInfo.DeflateCompressionLevel,
true);
}
case ZipCompressionMethod.BZip2:
@@ -254,7 +229,7 @@ namespace SharpCompress.Writer.Zip
}
default:
{
throw new NotSupportedException("CompressionMethod: " + writer.compression);
throw new NotSupportedException("CompressionMethod: " + writer.zipCompressionInfo.Compression);
}
}
}

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LinqBridge" version="1.3.0" targetFramework="net20" />
</packages>

View File

@@ -128,5 +128,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\SharpCompress\packages.config" />
</repositories>