Compare commits

...

2 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
6 changed files with 90 additions and 34 deletions

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

@@ -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.3",
"version": "0.12.4",
"title": "SharpCompress - Pure C# Decompression/Compression",
"authors": [ "Adam Hathcock" ],
"language": "en-US",
@@ -11,29 +11,19 @@
"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": {
@@ -44,8 +34,6 @@
},
".NETPortable,Version=v4.5,Profile=Profile259": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "NO_FILE", "NO_CRYPTO", "SILVERLIGHT" ]
},
"frameworkAssemblies": {
@@ -64,8 +52,6 @@
},
"netstandard1.0": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "NO_FILE", "NO_CRYPTO" ]
},
"dependencies": {
@@ -79,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);