Compare commits

...

7 Commits

Author SHA1 Message Date
Adam Hathcock
b0b62fcf91 Try to fix frameworks again by matching JSON.NET 2016-08-12 12:14:22 +01:00
Adam Hathcock
bd8ba7b854 Test with ForwardOnlyStream. RewindableStream shouldn't corrupt a ForwardOnlyStream (#161) 2016-08-12 11:56:49 +01:00
Adam Hathcock
3a52c68270 0.12.3 2016-07-22 16:50:33 +01:00
Adam Hathcock
89fd778bd8 Make all framework assemblies be build targets as a fix https://github.com/NuGet/Home/issues/3103 2016-07-22 16:47:59 +01:00
Tobias Käs
6e3e8343a8 Ignore unofficial extension of file attributes. (#153)
The high bits may contain posix file attributes when the archive was written by certain third party 7z implementations. These must be removed before we can interpret the attributes as windows (or .NET) file attributes.
2016-07-21 11:06:42 +01:00
Tobias Käs
9224237a99 Fix for issue #73 (#154)
7z archives may require alternating reads from multiple substreams so it is important to seek before reading from the underlying stream. To keep performance at an acceptable level it is necessary to perform buffering because seeking on every single one-byte-read will destroy performance.
2016-07-21 11:06:25 +01:00
Adam Hathcock
8d16925662 Add Profile259 2016-07-18 14:37:39 +01:00
11 changed files with 245 additions and 37 deletions

View File

@@ -34,6 +34,13 @@ I'm always looking for help or ideas. Please submit code or email with ideas. Un
## Version Log
### Version 0.12.3
* 7Zip fixes https://github.com/adamhathcock/sharpcompress/issues/73
* Maybe all profiles will work with project.json now
### Version 0.12.2
* Support Profile 259 again
### Version 0.12.1
* Support Silverlight 5

View File

@@ -895,6 +895,26 @@ namespace SharpCompress.Common.SevenZip
#endif
ReadAttributeVector(dataVector, numFiles, delegate(int i, uint? attr)
{
// Some third party implementations established an unofficial extension
// of the 7z archive format by placing posix file attributes in the high
// bits of the windows file attributes. This makes use of the fact that
// the official implementation does not perform checks on this value.
//
// Newer versions of the official 7z GUI client will try to parse this
// extension, thus acknowledging the unofficial use of these bits.
//
// For us it is safe to just discard the upper bits if they are set and
// keep the windows attributes from the lower bits (which should be set
// properly even if posix file attributes are present, in order to be
// compatible with older 7z archive readers)
//
// Note that the 15th bit is used by some implementations to indicate
// presence of the extension, but not all implementations do that so
// we can't trust that bit and must ignore it.
//
if (attr.HasValue && (attr.Value >> 16) != 0)
attr = attr.Value & 0x7FFFu;
db.Files[i].Attrib = attr;
#if DEBUG
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));

View File

@@ -31,7 +31,7 @@ namespace SharpCompress.Common.Zip
FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
{
reader = (lastEntryHeader.Part as StreamingZipFilePart).FixStreamedFileLocation(ref rewindableStream);
long pos = rewindableStream.Position;
long? pos = rewindableStream.CanSeek ? (long?)rewindableStream.Position : null;
uint crc = reader.ReadUInt32();
if (crc == POST_DATA_DESCRIPTOR)
{
@@ -40,7 +40,10 @@ namespace SharpCompress.Common.Zip
lastEntryHeader.Crc = crc;
lastEntryHeader.CompressedSize = reader.ReadUInt32();
lastEntryHeader.UncompressedSize = reader.ReadUInt32();
lastEntryHeader.DataStartPosition = pos - lastEntryHeader.CompressedSize;
if (pos.HasValue)
{
lastEntryHeader.DataStartPosition = pos - lastEntryHeader.CompressedSize;
}
}
lastEntryHeader = null;
uint headerBytes = reader.ReadUInt32();

View File

@@ -355,7 +355,7 @@ namespace SharpCompress.Compressor.Deflate
}
}
public String FileName
public string FileName
{
get { return fileName; }
set
@@ -372,10 +372,20 @@ namespace SharpCompress.Compressor.Deflate
if (fileName.EndsWith("\\"))
throw new InvalidOperationException("Illegal filename");
if (fileName.IndexOf("\\") != -1)
var index = fileName.IndexOf("\\");
if (index != -1)
{
// trim any leading path
fileName = Path.GetFileName(fileName);
int length = fileName.Length;
int num = length;
while (--num >= 0)
{
char c = fileName[num];
if (c == '\\')
{
fileName = fileName.Substring(num + 1, length - num - 1);
}
}
}
}
}

View File

@@ -162,7 +162,7 @@ namespace SharpCompress.Compressor.LZMA
Stream[] inStreams = new Stream[folderInfo.PackStreams.Count];
for (int j = 0; j < folderInfo.PackStreams.Count; j++)
{
inStreams[j] = new ReadOnlySubStream(inStream, startPos, packSizes[j]);
inStreams[j] = new BufferedSubStream(inStream, startPos, packSizes[j]);
startPos += packSizes[j];
}

View File

@@ -0,0 +1,105 @@
using System.IO;
namespace SharpCompress.IO
{
internal class BufferedSubStream : Stream
{
private long position;
private int cacheOffset;
private int cacheLength;
private byte[] cache;
public BufferedSubStream(Stream stream, long origin, long bytesToRead)
{
Stream = stream;
position = origin;
BytesLeftToRead = bytesToRead;
cache = new byte[32 << 10];
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
//Stream.Dispose();
}
}
private long BytesLeftToRead { get; set; }
public Stream Stream { get; private set; }
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 System.NotSupportedException();
}
public override long Length
{
get { throw new System.NotSupportedException(); }
}
public override long Position
{
get { throw new System.NotSupportedException(); }
set { throw new System.NotSupportedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
if (count > BytesLeftToRead)
count = (int)BytesLeftToRead;
if (count > 0)
{
if (cacheLength == 0)
{
cacheOffset = 0;
Stream.Position = position;
cacheLength = Stream.Read(cache, 0, cache.Length);
position += cacheLength;
}
if (count > cacheLength)
count = cacheLength;
System.Buffer.BlockCopy(cache, cacheOffset, buffer, offset, count);
cacheOffset += count;
cacheLength -= count;
BytesLeftToRead -= count;
}
return count;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new System.NotSupportedException();
}
public override void SetLength(long value)
{
throw new System.NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new System.NotSupportedException();
}
}
}

View File

@@ -72,10 +72,7 @@ namespace SharpCompress.IO
get { return true; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek => stream.CanSeek;
public override bool CanWrite
{

View File

@@ -1,5 +1,5 @@
{
"version": "0.12.1",
"version": "0.12.4",
"title": "SharpCompress - Pure C# Decompression/Compression",
"authors": [ "Adam Hathcock" ],
"language": "en-US",
@@ -11,41 +11,47 @@
"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.",
"requireLicenseAcceptance": false
},
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
},
"frameworks": {
"net35": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
"net40": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
"net45": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
"sl5": {
".NETPortable,Version=v4.0,Profile=Profile328": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "NO_FILE", "NO_CRYPTO", "SILVERLIGHT" ]
},
"frameworkAssemblies": {
"mscorlib": "",
"System": "",
"System.Core": ""
"mscorlib": { "type": "build" },
"System": { "type": "build" },
"System.Core": { "type": "build" }
}
},
".NETPortable,Version=v4.5,Profile=Profile259": {
"buildOptions": {
"define": [ "NO_FILE", "NO_CRYPTO", "SILVERLIGHT" ]
},
"frameworkAssemblies": {
"System": { "type": "build" },
"System.Collections": { "type": "build" },
"System.Core": { "type": "build" },
"System.Diagnostics.Debug": { "type": "build" },
"System.IO": { "type": "build" },
"System.Linq": { "type": "build" },
"System.Linq.Expressions": { "type": "build" },
"System.Resources.ResourceManager": { "type": "build" },
"System.Runtime": { "type": "build" },
"System.Runtime.Extensions": { "type": "build" },
"System.Text.Encoding": { "type": "build" }
}
},
"netstandard1.0": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "NO_FILE", "NO_CRYPTO" ]
},
"dependencies": {
@@ -59,10 +65,6 @@
}
},
"netstandard1.3": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
},
"dependencies": {
"System.Collections": "4.0.11",
"System.Diagnostics.Debug": "4.0.11",

View File

@@ -0,0 +1,64 @@
using System;
using System.IO;
namespace SharpCompress.Test
{
public class ForwardOnlyStream : Stream
{
private readonly Stream stream;
public bool IsDisposed { get; private set; }
public ForwardOnlyStream(Stream stream)
{
this.stream = stream;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
stream.Dispose();
IsDisposed = true;
}
public override bool CanRead => true;
public override bool CanSeek => false;
public override bool CanWrite => 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)
{
return stream.Read(buffer, offset, count);
}
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();
}
}
}

View File

@@ -18,7 +18,7 @@ namespace SharpCompress.Test
{
foreach (var path in testArchives)
{
using (Stream stream = File.OpenRead(path))
using (Stream stream = new ForwardOnlyStream(File.OpenRead(path)))
using (IReader reader = ReaderFactory.Open(stream))
{
UseReader(this, reader, expectedCompression);

View File

@@ -17,7 +17,7 @@
},
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0",
"SharpCompress": "0.12.1",
"SharpCompress": "0.12.2",
"xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029"
}