Compare commits

...

3 Commits
0.10 ... 0.10.1

Author SHA1 Message Date
Adam Hathcock
8109ae003d 0.10.1 packing 2013-08-11 09:51:05 +01:00
Adam Hathcock
8325b919ce Version 0.10.1 2013-08-11 09:47:00 +01:00
Adam Hathcock
61c97faf6c Remove needless sync stream. 2013-08-11 09:45:46 +01:00
10 changed files with 18 additions and 135 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>sharpcompress</id>
<version>0.10</version>
<version>0.10.1</version>
<title>SharpCompress - Pure C# Decompression/Compression</title>
<authors>Adam Hathcock</authors>
<owners>Adam Hathcock</owners>

View File

@@ -21,6 +21,9 @@ TODOs (always lots):
* Zip64
* Multi-volume Zip support.
Version 0.10.1:
==============
- Fixed 7Zip extraction performance problem
Version 0.10:
==============

View File

@@ -2,6 +2,7 @@
using System.IO;
using SharpCompress.Common.SevenZip;
using SharpCompress.Compressor.LZMA.Utilites;
using SharpCompress.IO;
namespace SharpCompress.Compressor.LZMA
{
@@ -158,12 +159,10 @@ namespace SharpCompress.Compressor.LZMA
if (!folderInfo.CheckStructure())
throw new NotSupportedException("Unsupported stream binding structure.");
// We have multiple views into the same stream which will be used by several threads - need to sync those.
object sync = new object();
Stream[] inStreams = new Stream[folderInfo.PackStreams.Count];
for (int j = 0; j < folderInfo.PackStreams.Count; j++)
{
inStreams[j] = new SyncStreamView(sync, inStream, startPos, packSizes[j]);
inStreams[j] = new ReadOnlySubStream(inStream, startPos, packSizes[j]);
startPos += packSizes[j];
}

View File

@@ -1,120 +0,0 @@
using System;
using System.IO;
namespace SharpCompress.Compressor.LZMA.Utilites
{
/// <summary>
/// Allows reading the same stream from multiple threads by synchronizing read access.
/// </summary>
internal class SyncStreamView : Stream
{
private object mSync;
private Stream mStream;
private long mOrigin;
private long mEnding;
private long mOffset;
private bool isDisposed;
public SyncStreamView(object sync, Stream stream, long origin, long length)
{
mSync = sync;
mStream = stream;
mOrigin = origin;
mEnding = checked(origin + length);
mOffset = 0;
}
protected override void Dispose(bool disposing)
{
if (isDisposed)
{
return;
}
isDisposed = true;
base.Dispose(disposing);
mStream.Dispose();
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush()
{
throw new InvalidOperationException();
}
public override long Length
{
get { return mEnding - mOrigin; }
}
public override long Position
{
get { return mOffset; }
set
{
if (value < 0 || value > Length)
throw new ArgumentOutOfRangeException("value");
mOffset = value;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
long remaining = mEnding - mOrigin - mOffset;
if (count > remaining)
count = (int)remaining;
if (count == 0)
return 0;
int delta;
lock (mSync)
{
mStream.Position = mOrigin + mOffset;
delta = mStream.Read(buffer, offset, count);
}
mOffset += delta;
return delta;
}
public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
return Position = offset;
case SeekOrigin.Current:
return Position += offset;
case SeekOrigin.End:
return Position = Length + offset;
default:
throw new ArgumentOutOfRangeException("origin");
}
}
public override void SetLength(long value)
{
throw new InvalidOperationException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new InvalidOperationException();
}
}
}

View File

@@ -5,8 +5,17 @@ namespace SharpCompress.IO
internal class ReadOnlySubStream : Stream
{
public ReadOnlySubStream(Stream stream, long bytesToRead)
: this(stream, null, bytesToRead)
{
}
public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead)
{
Stream = stream;
if (origin != null)
{
stream.Position = origin.Value;
}
BytesLeftToRead = bytesToRead;
}
@@ -57,7 +66,7 @@ namespace SharpCompress.IO
{
if (BytesLeftToRead < count)
{
count = (int) BytesLeftToRead;
count = (int)BytesLeftToRead;
}
int read = Stream.Read(buffer, offset, count);
if (read > 0)

View File

@@ -203,7 +203,6 @@
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs" />
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs" />
<Compile Include="Compressor\LZMA\Utilites\UnpackSubStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\Utils.cs" />
<Compile Include="Compressor\PPMd\H\FreqData.cs" />

View File

@@ -207,9 +207,6 @@
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\Utils.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -259,7 +259,6 @@
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs" />
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs" />
<Compile Include="Compressor\LZMA\Utilites\UnpackSubStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\Utils.cs" />
<Compile Include="Compressor\PPMd\H\FreqData.cs" />

View File

@@ -209,9 +209,6 @@
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\Utils.cs">
<SubType>Code</SubType>
</Compile>

View File

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