mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 13:34:59 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8109ae003d | ||
|
|
8325b919ce | ||
|
|
61c97faf6c |
@@ -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>
|
||||
|
||||
@@ -21,6 +21,9 @@ TODOs (always lots):
|
||||
* Zip64
|
||||
* Multi-volume Zip support.
|
||||
|
||||
Version 0.10.1:
|
||||
==============
|
||||
- Fixed 7Zip extraction performance problem
|
||||
|
||||
Version 0.10:
|
||||
==============
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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")]
|
||||
Reference in New Issue
Block a user