Merge branch 'master' into dnx

Conflicts:
	NuGet/sharpcompress.nuspec
	SharpCompress/Common/Zip/WinzipAesCryptoStream.Portable.cs
	SharpCompress/Common/Zip/WinzipAesEncryptionData.Portable.cs
	SharpCompress/Crypto/PBKDF2.cs
	SharpCompress/SharpCompress.Portable.csproj
	SharpCompress/SharpCompress.PortableTest.csproj
	SharpCompress/SharpCompress.Unsigned.csproj
	SharpCompress/SharpCompress.WindowsStore.csproj
	SharpCompress/SharpCompress.csproj
	src/SharpCompress/Archive/ArchiveFactory.cs
	src/SharpCompress/Archive/Rar/FileInfoRarFilePart.cs
	src/SharpCompress/Archive/Rar/RarArchive.cs
	src/SharpCompress/Archive/Rar/RarArchiveEntry.cs
	src/SharpCompress/Archive/SevenZip/SevenZipArchiveEntry.cs
	src/SharpCompress/Common/GZip/GZipFilePart.cs
	src/SharpCompress/Common/GZip/GZipVolume.cs
	src/SharpCompress/Common/Rar/Headers/MarkHeader.cs
	src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs
	src/SharpCompress/Common/SevenZip/ArchiveReader.cs
	src/SharpCompress/Common/SevenZip/DataReader.cs
	src/SharpCompress/Common/Tar/Headers/TarHeader.cs
	src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
	src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs
	src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs
	src/SharpCompress/Common/Zip/ZipFilePart.cs
	src/SharpCompress/Compressor/Deflate/GZipStream.cs
	src/SharpCompress/Compressor/Deflate/Inflate.cs
	src/SharpCompress/Compressor/Deflate/ZlibBaseStream.cs
	src/SharpCompress/Compressor/LZMA/Bcj2DecoderStream.cs
	src/SharpCompress/Compressor/LZMA/LzmaStream.cs
	src/SharpCompress/Compressor/PPMd/H/FreqData.cs
	src/SharpCompress/Compressor/PPMd/H/PPMContext.cs
	src/SharpCompress/Compressor/PPMd/H/RarMemBlock.cs
	src/SharpCompress/Compressor/PPMd/H/RarNode.cs
	src/SharpCompress/Compressor/PPMd/H/State.cs
	src/SharpCompress/Compressor/PPMd/PpmdProperties.cs
	src/SharpCompress/Compressor/Rar/VM/RarVM.cs
	src/SharpCompress/EnumExtensions.cs
	src/SharpCompress/IO/MarkingBinaryReader.cs
	src/SharpCompress/Reader/ReaderFactory.cs
	src/SharpCompress/Utility.cs
	src/SharpCompress/Writer/IWriter.Extensions.cs
	src/SharpCompress/Writer/Zip/ZipCentralDirectoryEntry.cs
	src/SharpCompress/Writer/Zip/ZipWriter.cs
	test/SharpCompress.Test/Tar/TarArchiveTests.cs
	test/SharpCompress.Test/Tar/TarReaderTests.cs
This commit is contained in:
Adam Hathcock
2016-02-13 09:24:44 +00:00
39 changed files with 2292 additions and 403 deletions

View File

@@ -31,12 +31,6 @@ namespace SharpCompress.Archive
return ZipArchive.Open(stream, options, null);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Seek(0, SeekOrigin.Begin);
return TarArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (SevenZipArchive.IsSevenZipFile(stream))
{
stream.Seek(0, SeekOrigin.Begin);
@@ -49,11 +43,17 @@ namespace SharpCompress.Archive
return GZipArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
if (RarArchive.IsRarFile(stream, options))
{
stream.Seek(0, SeekOrigin.Begin);
return RarArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Seek(0, SeekOrigin.Begin);
return TarArchive.Open(stream, options);
}
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
}
@@ -126,12 +126,6 @@ namespace SharpCompress.Archive
return ZipArchive.Open(fileInfo, options, null);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Dispose();
return TarArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (SevenZipArchive.IsSevenZipFile(stream))
{
stream.Dispose();
@@ -144,11 +138,17 @@ namespace SharpCompress.Archive
return GZipArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
if (RarArchive.IsRarFile(stream, options))
{
stream.Dispose();
return RarArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Dispose();
return TarArchive.Open(fileInfo, options);
}
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
}
}

View File

@@ -7,12 +7,9 @@ namespace SharpCompress.Archive.Rar
{
internal class FileInfoRarFilePart : SeekableFilePart
{
private readonly FileInfoRarArchiveVolume volume;
internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
: base(mh, fh, volume.Stream, volume.Password)
{
this.volume = volume;
FileInfo = fi;
}

View File

@@ -152,12 +152,8 @@ namespace SharpCompress.Archive.Rar
try
{
var headerFactory = new RarHeaderFactory(StreamingMode.Seekable, options);
RarHeader header = headerFactory.ReadHeaders(stream).FirstOrDefault();
if (header == null)
{
return false;
}
return Enum.IsDefined(typeof (HeaderType), header.HeaderType);
var markHeader = headerFactory.ReadHeaders(stream).FirstOrDefault() as MarkHeader;
return markHeader != null && markHeader.IsValid();
}
catch
{

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -73,8 +74,11 @@ namespace SharpCompress.Archive.Rar
public Stream OpenEntryStream()
{
return new RarStream(archive.Unpack, FileHeader,
new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive));
if (archive.IsSolid)
{
throw new InvalidOperationException("Use ExtractAllEntries to extract SOLID archives.");
}
return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive));
}
public bool IsComplete

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using SharpCompress.Common.SevenZip;
namespace SharpCompress.Archive.SevenZip

View File

@@ -3,6 +3,7 @@ using System.IO;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.Compressor;
using SharpCompress.Compressor.Deflate;
using SharpCompress.Converter;
namespace SharpCompress.Common.GZip
{
@@ -50,7 +51,7 @@ namespace SharpCompress.Common.GZip
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
throw new ZlibException("Bad GZIP header.");
Int32 timet = BitConverter.ToInt32(header, 4);
Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
DateModified = TarHeader.Epoch.AddSeconds(timet);
if ((header[3] & 0x04) == 0x04)
{

View File

@@ -4,10 +4,6 @@ namespace SharpCompress.Common.GZip
{
public class GZipVolume : Volume
{
#if !NO_FILE
private readonly FileInfo fileInfo;
#endif
public GZipVolume(Stream stream, Options options)
: base(stream, options)
{
@@ -17,7 +13,6 @@ namespace SharpCompress.Common.GZip
public GZipVolume(FileInfo fileInfo, Options options)
: base(fileInfo.OpenRead(), options)
{
this.fileInfo = fileInfo;
}
#endif

View File

@@ -10,48 +10,15 @@ namespace SharpCompress.Common.Rar.Headers
internal bool IsValid()
{
if (!(HeadCRC == 0x6152))
{
return false;
}
if (!(HeaderType == HeaderType.MarkHeader))
{
return false;
}
if (!(Flags == 0x1a21))
{
return false;
}
if (!(HeaderSize == BaseBlockSize))
{
return false;
}
return true;
}
// Rar old signature: 52 45 7E 5E (not supported)
internal bool IsSignature()
{
bool valid = false;
/*byte[] d = new byte[BaseBlock.BaseBlockSize];
BinaryWriter writer = new BinaryWriter();
writer.Write(HeadCRC);
writer.Write((byte)HeaderType);
writer.Write(flags);
writer.Write(HeaderSize);
writer.Flush
if (d[0] == 0x52) {
if (d[1]==0x45 && d[2]==0x7e && d[3]==0x5e) {
oldFormat=true;
valid=true;
}
else if (d[1]==0x61 && d[2]==0x72 && d[3]==0x21 && d[4]==0x1a &&
d[5]==0x07 && d[6]==0x00) {
oldFormat=false;
valid=true;
}
}*/
return valid;
// Rar4 signature: 52 61 72 21 1A 07 00
return HeadCRC == 0x6152 &&
HeaderType == HeaderType.MarkHeader &&
Flags == 0x1A21 &&
HeaderSize == 0x07;
// Rar5 signature: 52 61 72 21 1A 07 10 00 (not supported yet)
}
internal bool OldFormat { get; private set; }

View File

@@ -1198,14 +1198,12 @@ namespace SharpCompress.Common.SevenZip
private class FolderUnpackStream : Stream
{
private ArchiveDatabase _db;
private int _otherIndex;
private int _startIndex;
private List<bool> _extractStatuses;
public FolderUnpackStream(ArchiveDatabase db, int p, int startIndex, List<bool> list)
{
this._db = db;
this._otherIndex = p;
this._startIndex = startIndex;
this._extractStatuses = list;
}
@@ -1275,12 +1273,7 @@ namespace SharpCompress.Common.SevenZip
private void OpenFile()
{
bool skip = !_extractStatuses[_currentIndex];
int index = _startIndex + _currentIndex;
int realIndex = _otherIndex + index;
//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

View File

@@ -34,7 +34,6 @@ namespace SharpCompress.Common.SevenZip
#region Variables
private byte[] _buffer;
private int _origin;
private int _offset;
private int _ending;
@@ -45,7 +44,6 @@ namespace SharpCompress.Common.SevenZip
public DataReader(byte[] buffer, int offset, int length)
{
_buffer = buffer;
_origin = offset;
_offset = offset;
_ending = offset + length;
}

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Common.Tar.Headers
{
@@ -45,7 +46,7 @@ namespace SharpCompress.Common.Tar.Headers
if (Size >= 0x1FFFFFFFF)
{
byte[] bytes = BitConverter.GetBytes(Utility.HostToNetworkOrder(Size));
byte[] bytes = DataConverter.BigEndian.GetBytes(Size);
var bytes12 = new byte[12];
bytes.CopyTo(bytes12, 12 - bytes.Length);
bytes12[0] |= 0x80;
@@ -96,8 +97,7 @@ namespace SharpCompress.Common.Tar.Headers
EntryType = (EntryType) buffer[156];
if ((buffer[124] & 0x80) == 0x80) // if size in binary
{
long sizeBigEndian = BitConverter.ToInt64(buffer, 0x80);
Size = Utility.NetworkToHostOrder(sizeBigEndian);
Size = DataConverter.BigEndian.GetInt64(buffer, 0x80);
}
else
{

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Common.Zip.Headers
{
@@ -68,13 +69,13 @@ namespace SharpCompress.Common.Zip.Headers
{
for (int i = 0; i < extra.Length-4;)
{
ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);
ExtraDataType type = (ExtraDataType)DataConverter.LittleEndian.GetUInt16(extra, i);
if (!Enum.IsDefined(typeof (ExtraDataType), type))
{
type = ExtraDataType.NotImplementedExtraData;
}
ushort length = BitConverter.ToUInt16(extra, i + 2);
ushort length = DataConverter.LittleEndian.GetUInt16(extra, i + 2);
byte[] data = new byte[length];
Buffer.BlockCopy(extra, i + 4, data, 0, length);
Extra.Add(LocalEntryHeaderExtraFactory.Create(type,length,data));

View File

@@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Security.Cryptography;
using SharpCompress.Converter;
namespace SharpCompress.Common.Zip
{
@@ -118,7 +119,7 @@ namespace SharpCompress.Common.Zip
: bytesRemaining;
// update the counter
Array.Copy(BitConverter.GetBytes(nonce++), 0, counter, 0, 4);
DataConverter.LittleEndian.PutBytes(counter, 0, nonce++);
// Determine if this is the final block
if ((bytesToRead == bytesRemaining) && (totalBytesLeftToRead == 0))

View File

@@ -1,6 +1,6 @@
#if !NO_CRYPTO
using System;
using System.Security.Cryptography;
using SharpCompress.Converter;
using System.Text;
namespace SharpCompress.Common.Zip
@@ -63,10 +63,10 @@ namespace SharpCompress.Common.Zip
IvBytes = rfc2898.GetBytes(KeySizeInBytes);
generatedVerifyValue = rfc2898.GetBytes(2);
short verify = BitConverter.ToInt16(passwordVerifyValue, 0);
short verify = DataConverter.LittleEndian.GetInt16(passwordVerifyValue, 0);
if (password != null)
{
short generated = BitConverter.ToInt16(generatedVerifyValue, 0);
short generated = DataConverter.LittleEndian.GetInt16(generatedVerifyValue, 0);
if (verify != generated)
throw new InvalidFormatException("bad password");
}

View File

@@ -7,6 +7,7 @@ using SharpCompress.Compressor.BZip2;
using SharpCompress.Compressor.Deflate;
using SharpCompress.Compressor.LZMA;
using SharpCompress.Compressor.PPMd;
using SharpCompress.Converter;
using SharpCompress.IO;
namespace SharpCompress.Common.Zip
@@ -108,19 +109,19 @@ namespace SharpCompress.Common.Zip
{
throw new InvalidFormatException("Winzip data length is not 7.");
}
ushort method = BitConverter.ToUInt16(data.DataBytes, 0);
ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);
if (method != 0x01 && method != 0x02)
{
throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata");
}
ushort vendorId = BitConverter.ToUInt16(data.DataBytes, 2);
ushort vendorId = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 2);
if (vendorId != 0x4541)
{
throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata");
}
Header.CompressionMethod = (ZipCompressionMethod)BitConverter.ToUInt16(data.DataBytes, 5);
Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5);
return CreateDecompressionStream(stream);
}
default:

View File

@@ -30,6 +30,7 @@
using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.Deflate
{
@@ -416,7 +417,7 @@ namespace SharpCompress.Compressor.Deflate
LastModified = DateTime.Now;
TimeSpan delta = LastModified.Value - UnixEpoch;
var timet = (Int32) delta.TotalSeconds;
Array.Copy(BitConverter.GetBytes(timet), 0, header, i, 4);
DataConverter.LittleEndian.PutBytes(header, i, timet);
i += 4;
// xflg

View File

@@ -895,6 +895,11 @@ namespace SharpCompress.Compressor.Deflate
r = ZlibConstants.Z_OK;
else
{
// Handling missing trailing bit(s)
var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3;
if (k >= tree[tmp_tindex + 1])
break;
blocks.bitb = b;
blocks.bitk = k;
z.AvailableBytesIn = n;
@@ -998,6 +1003,11 @@ namespace SharpCompress.Compressor.Deflate
r = ZlibConstants.Z_OK;
else
{
// Handling missing trailing bit(s)
var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3;
if (k >= tree[tmp_tindex + 1])
break;
blocks.bitb = b;
blocks.bitk = k;
z.AvailableBytesIn = n;

View File

@@ -27,6 +27,7 @@
using System;
using SharpCompress.Common;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.Deflate
{
@@ -221,9 +222,9 @@ namespace SharpCompress.Compressor.Deflate
{
// Emit the GZIP trailer: CRC32 and size mod 2^32
int c1 = crc.Crc32Result;
_stream.Write(BitConverter.GetBytes(c1), 0, 4);
_stream.Write(DataConverter.LittleEndian.GetBytes(c1), 0, 4);
int c2 = (Int32)(crc.TotalBytesRead & 0x00000000FFFFFFFF);
_stream.Write(BitConverter.GetBytes(c2), 0, 4);
_stream.Write(DataConverter.LittleEndian.GetBytes(c2), 0, 4);
}
else
{
@@ -267,9 +268,9 @@ namespace SharpCompress.Compressor.Deflate
}
Int32 crc32_expected = BitConverter.ToInt32(trailer, 0);
Int32 crc32_expected = DataConverter.LittleEndian.GetInt32(trailer, 0);
Int32 crc32_actual = crc.Crc32Result;
Int32 isize_expected = BitConverter.ToInt32(trailer, 4);
Int32 isize_expected = DataConverter.LittleEndian.GetInt32(trailer, 4);
Int32 isize_actual = (Int32)(_z.TotalBytesOut & 0x00000000FFFFFFFF);
if (crc32_actual != crc32_expected)
@@ -405,7 +406,7 @@ namespace SharpCompress.Compressor.Deflate
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
throw new ZlibException("Bad GZIP header.");
Int32 timet = BitConverter.ToInt32(header, 4);
Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
_GzipMtime = TarHeader.Epoch.AddSeconds(timet);
totalBytesRead += n;
if ((header[3] & 0x04) == 0x04)

View File

@@ -99,7 +99,6 @@ namespace SharpCompress.Compressor.LZMA
private RangeDecoder mRangeDecoder;
private StatusDecoder[] mStatusDecoder;
private long mWritten;
private long mLimit;
private IEnumerator<byte> mIter;
private bool mFinished;
private bool isDisposed;
@@ -112,7 +111,6 @@ namespace SharpCompress.Compressor.LZMA
if (streams.Length != 4)
throw new NotSupportedException();
mLimit = limit;
mMainStream = streams[0];
mCallStream = streams[1];
mJumpStream = streams[2];

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using SharpCompress.Compressor.LZMA.LZ;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.LZMA
{
@@ -56,7 +57,7 @@ namespace SharpCompress.Compressor.LZMA
if (!isLZMA2)
{
dictionarySize = BitConverter.ToInt32(properties, 1);
dictionarySize = DataConverter.LittleEndian.GetInt32(properties, 1);
outWindow.Create(dictionarySize);
if (presetDictionary != null)
outWindow.Train(presetDictionary);

View File

@@ -1,4 +1,5 @@
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd.H
{
@@ -19,9 +20,9 @@ namespace SharpCompress.Compressor.PPMd.H
internal int SummFreq
{
get { return Utility.readShortLittleEndian(Memory, Address) & 0xffff; }
get { return DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff; }
set { Utility.WriteLittleEndian(Memory, Address, (short) value); }
set { DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value); }
}
internal FreqData Initialize(byte[] mem)
@@ -31,12 +32,14 @@ namespace SharpCompress.Compressor.PPMd.H
internal void IncrementSummFreq(int dSummFreq)
{
Utility.incShortLittleEndian(Memory, Address, (short) dSummFreq);
short summFreq = DataConverter.LittleEndian.GetInt16(Memory, Address);
summFreq += (short)dSummFreq;
DataConverter.LittleEndian.PutBytes(Memory, Address, summFreq);
}
internal int GetStats()
{
return Utility.readIntLittleEndian(Memory, Address + 2);
return DataConverter.LittleEndian.GetInt32(Memory, Address + 2);
}
internal virtual void SetStats(State state)
@@ -46,7 +49,7 @@ namespace SharpCompress.Compressor.PPMd.H
internal void SetStats(int state)
{
Utility.WriteLittleEndian(Memory, Address + 2, state);
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, state);
}
public override System.String ToString()

View File

@@ -1,4 +1,5 @@
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd.H
{
@@ -21,7 +22,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
numStats = Utility.readShortLittleEndian(Memory, Address) & 0xffff;
numStats = DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff;
}
return numStats;
}
@@ -31,7 +32,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.numStats = value & 0xffff;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address, (short) value);
DataConverter.LittleEndian.PutBytes(Memory, Address, (short) value);
}
}
}
@@ -103,7 +104,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
suffix = Utility.readIntLittleEndian(Memory, Address + 8);
suffix = DataConverter.LittleEndian.GetInt32(Memory, Address + 8);
}
return suffix;
}
@@ -118,7 +119,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.suffix = suffix;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address + 8, suffix);
DataConverter.LittleEndian.PutBytes(Memory, Address + 8, suffix);
}
}

View File

@@ -1,3 +1,5 @@
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd.H
{
internal class RarMemBlock : Pointer
@@ -19,7 +21,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
stamp = Utility.readShortLittleEndian(Memory, Address) & 0xffff;
stamp = DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff;
}
return stamp;
}
@@ -29,7 +31,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.stamp = value;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address, (short) value);
DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value);
}
}
}
@@ -60,7 +62,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
next = Utility.readIntLittleEndian(Memory, Address + 4);
next = DataConverter.LittleEndian.GetInt32(Memory, Address + 4);
}
return next;
}
@@ -75,7 +77,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.next = next;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address + 4, next);
DataConverter.LittleEndian.PutBytes(Memory, Address + 4, next);
}
}
@@ -83,7 +85,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
NU = Utility.readShortLittleEndian(Memory, Address + 2) & 0xffff;
NU = DataConverter.LittleEndian.GetInt16(Memory, Address + 2) & 0xffff;
}
return NU;
}
@@ -93,7 +95,7 @@ namespace SharpCompress.Compressor.PPMd.H
NU = nu & 0xffff;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address + 2, (short) nu);
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, (short)nu);
}
}
@@ -101,7 +103,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
prev = Utility.readIntLittleEndian(Memory, Address + 8);
prev = DataConverter.LittleEndian.GetInt32(Memory, Address + 8);
}
return prev;
}
@@ -116,7 +118,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.prev = prev;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address + 8, prev);
DataConverter.LittleEndian.PutBytes(Memory, Address + 8, prev);
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd.H
{
@@ -17,7 +18,7 @@ namespace SharpCompress.Compressor.PPMd.H
{
if (Memory != null)
{
next = Utility.readIntLittleEndian(Memory, Address);
next = DataConverter.LittleEndian.GetInt32(Memory, Address);
}
return next;
}
@@ -32,7 +33,7 @@ namespace SharpCompress.Compressor.PPMd.H
this.next = next;
if (Memory != null)
{
Utility.WriteLittleEndian(Memory, Address, next);
DataConverter.LittleEndian.PutBytes(Memory, Address, next);
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Text;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd.H
{
@@ -38,7 +39,7 @@ namespace SharpCompress.Compressor.PPMd.H
internal int GetSuccessor()
{
return Utility.readIntLittleEndian(Memory, Address + 2);
return DataConverter.LittleEndian.GetInt32(Memory, Address + 2);
}
internal void SetSuccessor(PPMContext successor)
@@ -48,7 +49,7 @@ namespace SharpCompress.Compressor.PPMd.H
internal void SetSuccessor(int successor)
{
Utility.WriteLittleEndian(Memory, Address + 2, successor);
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, successor);
}
internal void SetValues(StateRef state)

View File

@@ -1,4 +1,5 @@
using System;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.PPMd
{
@@ -39,7 +40,7 @@ namespace SharpCompress.Compressor.PPMd
{
if (properties.Length == 2)
{
ushort props = BitConverter.ToUInt16(properties, 0);
ushort props = DataConverter.LittleEndian.GetUInt16(properties, 0);
AllocatorSize = (((props >> 4) & 0xff) + 1) << 20;
ModelOrder = (props & 0x0f) + 1;
ModelRestorationMethod = (I1.ModelRestorationMethod) (props >> 12);
@@ -47,7 +48,7 @@ namespace SharpCompress.Compressor.PPMd
else if (properties.Length == 5)
{
Version = PpmdVersion.H7z;
AllocatorSize = BitConverter.ToInt32(properties, 1);
AllocatorSize = DataConverter.LittleEndian.GetInt32(properties, 1);
ModelOrder = properties[0];
}
}
@@ -72,7 +73,7 @@ namespace SharpCompress.Compressor.PPMd
get
{
return
BitConverter.GetBytes(
DataConverter.LittleEndian.GetBytes(
(ushort)
((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort) ModelRestorationMethod << 12)));
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using SharpCompress.Converter;
namespace SharpCompress.Compressor.Rar.VM
{
@@ -77,11 +78,12 @@ namespace SharpCompress.Compressor.Rar.VM
{
if (IsVMMem(mem))
{
return Utility.readIntLittleEndian(mem, offset);
return DataConverter.LittleEndian.GetInt32(mem, offset);
}
else
{
return Utility.readIntBigEndian(mem, offset);
return DataConverter.BigEndian.GetInt32(mem, offset);
}
}
}
@@ -103,19 +105,11 @@ namespace SharpCompress.Compressor.Rar.VM
{
if (IsVMMem(mem))
{
Utility.WriteLittleEndian(mem, offset, value);
// Mem[offset + 0] = (byte) value;
// Mem[offset + 1] = (byte) (value >>> 8);
// Mem[offset + 2] = (byte) (value >>> 16);
// Mem[offset + 3] = (byte) (value >>> 24);
DataConverter.LittleEndian.PutBytes(mem, offset, value);
}
else
{
Utility.writeIntBigEndian(mem, offset, value);
// Mem[offset + 3] = (byte) value;
// Mem[offset + 2] = (byte) (value >>> 8);
// Mem[offset + 1] = (byte) (value >>> 16);
// Mem[offset + 0] = (byte) (value >>> 24);
DataConverter.BigEndian.PutBytes(mem, offset, value);
}
}
// #define SET_VALUE(ByteMode,Addr,Value) SetValue(ByteMode,(uint
@@ -136,12 +130,12 @@ namespace SharpCompress.Compressor.Rar.VM
if (cmdOp.Type == VMOpType.VM_OPREGMEM)
{
int pos = (cmdOp.Offset + cmdOp.Base) & VM_MEMMASK;
ret = Utility.readIntLittleEndian(Mem, pos);
ret = DataConverter.LittleEndian.GetInt32(Mem, pos);
}
else
{
int pos = cmdOp.Offset;
ret = Utility.readIntLittleEndian(Mem, pos);
ret = DataConverter.LittleEndian.GetInt32(Mem, pos);
}
return ret;
}

View File

@@ -1,4 +1,5 @@
using System;
#if NET35
using System;
namespace SharpCompress
{
@@ -12,4 +13,5 @@ namespace SharpCompress
return (value & flagVal) == flagVal;
}
}
}
}
#endif

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using SharpCompress.Converter;
namespace SharpCompress.IO
{
@@ -36,7 +37,7 @@ namespace SharpCompress.IO
public override bool ReadBoolean()
{
return BitConverter.ToBoolean(ReadBytes(1), 0);
return ReadBytes(1).Single() != 0;
}
public override byte ReadByte()
@@ -67,38 +68,27 @@ namespace SharpCompress.IO
public override decimal ReadDecimal()
{
return ByteArrayToDecimal(ReadBytes(16), 0);
}
private decimal ByteArrayToDecimal(byte[] src, int offset)
{
//http://stackoverflow.com/a/16984356/385387
var i1 = BitConverter.ToInt32(src, offset);
var i2 = BitConverter.ToInt32(src, offset + 4);
var i3 = BitConverter.ToInt32(src, offset + 8);
var i4 = BitConverter.ToInt32(src, offset + 12);
return new decimal(new[] { i1, i2, i3, i4 });
throw new NotSupportedException();
}
public override double ReadDouble()
{
return BitConverter.ToDouble(ReadBytes(8), 0);
throw new NotSupportedException();
}
public override short ReadInt16()
{
return BitConverter.ToInt16(ReadBytes(2), 0);
return DataConverter.LittleEndian.GetInt16(ReadBytes(2), 0);
}
public override int ReadInt32()
{
return BitConverter.ToInt32(ReadBytes(4), 0);
return DataConverter.LittleEndian.GetInt32(ReadBytes(4), 0);
}
public override long ReadInt64()
{
return BitConverter.ToInt64(ReadBytes(8), 0);
return DataConverter.LittleEndian.GetInt64(ReadBytes(8), 0);
}
public override sbyte ReadSByte()
@@ -108,7 +98,7 @@ namespace SharpCompress.IO
public override float ReadSingle()
{
return BitConverter.ToSingle(ReadBytes(4), 0);
throw new NotSupportedException();
}
public override string ReadString()
@@ -118,17 +108,17 @@ namespace SharpCompress.IO
public override ushort ReadUInt16()
{
return BitConverter.ToUInt16(ReadBytes(2), 0);
return DataConverter.LittleEndian.GetUInt16(ReadBytes(2), 0);
}
public override uint ReadUInt32()
{
return BitConverter.ToUInt32(ReadBytes(4), 0);
return DataConverter.LittleEndian.GetUInt32(ReadBytes(4), 0);
}
public override ulong ReadUInt64()
{
return BitConverter.ToUInt64(ReadBytes(8), 0);
return DataConverter.LittleEndian.GetUInt64(ReadBytes(8), 0);
}
}
}

View File

@@ -61,12 +61,6 @@ namespace SharpCompress.Reader
}
}
rewindableStream.Rewind(false);
if (TarArchive.IsTarFile(rewindableStream))
{
rewindableStream.Rewind(true);
return TarReader.Open(rewindableStream, options);
}
rewindableStream.Rewind(false);
if (RarArchive.IsRarFile(rewindableStream, options))
{
@@ -74,6 +68,12 @@ namespace SharpCompress.Reader
return RarReader.Open(rewindableStream, options);
}
rewindableStream.Rewind(false);
if (TarArchive.IsTarFile(rewindableStream))
{
rewindableStream.Rewind(true);
return TarReader.Open(rewindableStream, options);
}
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Reader Formats: Zip, GZip, BZip2, Tar, Rar");
}
}

View File

@@ -2,9 +2,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SharpCompress.Archive;
using SharpCompress.Common;
using SharpCompress.IO;
namespace SharpCompress
{
@@ -29,17 +26,6 @@ namespace SharpCompress
return (number >> bits) + (2 << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static int URShift(int number, long bits)
{
return URShift(number, (int)bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
@@ -54,17 +40,6 @@ namespace SharpCompress
return (number >> bits) + (2L << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static long URShift(long number, long bits)
{
return URShift(number, (int)bits);
}
/// <summary>
/// Fills the array with an specific value from an specific index to an specific index.
/// </summary>
@@ -120,139 +95,6 @@ namespace SharpCompress
}
}
/// <summary> Read a int value from the byte array at the given position (Big Endian)
///
/// </summary>
/// <param name="array">the array to read from
/// </param>
/// <param name="pos">the offset
/// </param>
/// <returns> the value
/// </returns>
public static int readIntBigEndian(byte[] array, int pos)
{
int temp = 0;
temp |= array[pos] & 0xff;
temp <<= 8;
temp |= array[pos + 1] & 0xff;
temp <<= 8;
temp |= array[pos + 2] & 0xff;
temp <<= 8;
temp |= array[pos + 3] & 0xff;
return temp;
}
/// <summary> Read a short value from the byte array at the given position (little
/// Endian)
///
/// </summary>
/// <param name="array">the array to read from
/// </param>
/// <param name="pos">the offset
/// </param>
/// <returns> the value
/// </returns>
public static short readShortLittleEndian(byte[] array, int pos)
{
return BitConverter.ToInt16(array, pos);
}
/// <summary> Read an int value from the byte array at the given position (little
/// Endian)
///
/// </summary>
/// <param name="array">the array to read from
/// </param>
/// <param name="pos">the offset
/// </param>
/// <returns> the value
/// </returns>
public static int readIntLittleEndian(byte[] array, int pos)
{
return BitConverter.ToInt32(array, pos);
}
/// <summary> Write an int value into the byte array at the given position (Big endian)
///
/// </summary>
/// <param name="array">the array
/// </param>
/// <param name="pos">the offset
/// </param>
/// <param name="value">the value to write
/// </param>
public static void writeIntBigEndian(byte[] array, int pos, int value)
{
array[pos] = (byte)((Utility.URShift(value, 24)) & 0xff);
array[pos + 1] = (byte)((Utility.URShift(value, 16)) & 0xff);
array[pos + 2] = (byte)((Utility.URShift(value, 8)) & 0xff);
array[pos + 3] = (byte)((value) & 0xff);
}
/// <summary> Write a short value into the byte array at the given position (little
/// endian)
///
/// </summary>
/// <param name="array">the array
/// </param>
/// <param name="pos">the offset
/// </param>
/// <param name="value">the value to write
/// </param>
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);
}
/// <summary> Increment a short value at the specified position by the specified amount
/// (little endian).
/// </summary>
public static void incShortLittleEndian(byte[] array, int pos, short incrementValue)
{
short existingValue = BitConverter.ToInt16(array, pos);
existingValue += incrementValue;
WriteLittleEndian(array, pos, existingValue);
//int c = Utility.URShift(((array[pos] & 0xff) + (dv & 0xff)), 8);
//array[pos] = (byte)(array[pos] + (dv & 0xff));
//if ((c > 0) || ((dv & 0xff00) != 0))
//{
// array[pos + 1] = (byte)(array[pos + 1] + ((Utility.URShift(dv, 8)) & 0xff) + c);
//}
}
/// <summary> Write an int value into the byte array at the given position (little
/// endian)
///
/// </summary>
/// <param name="array">the array
/// </param>
/// <param name="pos">the offset
/// </param>
/// <param name="value">the value to write
/// </param>
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);
}
public static void Initialize<T>(this T[] array, Func<T> func)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = func();
}
}
public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> source)
{
foreach (T item in source)
@@ -304,7 +146,7 @@ namespace SharpCompress
readCount = (int)advanceAmount;
}
read = source.Read(buffer, 0, readCount);
if (read < 0)
if (read <= 0)
{
break;
}
@@ -324,18 +166,6 @@ namespace SharpCompress
} while (source.Read(buffer, 0, buffer.Length) == buffer.Length);
}
public static byte[] UInt32ToBigEndianBytes(uint x)
{
return new byte[]
{
(byte) ((x >> 24) & 0xff),
(byte) ((x >> 16) & 0xff),
(byte) ((x >> 8) & 0xff),
(byte) (x & 0xff)
};
}
public static DateTime DosDateToDateTime(UInt16 iDate, UInt16 iTime)
{
int year = iDate / 512 + 1980;
@@ -449,32 +279,5 @@ namespace SharpCompress
{
Array.Copy(array, 0, destination, index, array.Length);
}
public static long HostToNetworkOrder(long host)
{
return (int)((long)HostToNetworkOrder((int)host)
& unchecked((long)(unchecked((ulong)-1))) << 32
| ((long)HostToNetworkOrder((int)((int)host >> 32)) & unchecked((long)(unchecked((ulong)-1)))));
}
public static int HostToNetworkOrder(int host)
{
return (int)((int)(HostToNetworkOrder((short)host) & -1) << 16 | (HostToNetworkOrder((short)(host >> 16)) & -1));
}
public static short HostToNetworkOrder(short host)
{
return (short)((int)(host & 255) << 8 | ((int)host >> 8 & 255));
}
public static long NetworkToHostOrder(long network)
{
return HostToNetworkOrder(network);
}
public static int NetworkToHostOrder(int network)
{
return HostToNetworkOrder(network);
}
public static short NetworkToHostOrder(short network)
{
return HostToNetworkOrder(network);
}
}
}

View File

@@ -3,6 +3,7 @@ using System.IO;
using System.Text;
using SharpCompress.Common.Zip;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.Converter;
namespace SharpCompress.Writer.Zip
{
@@ -32,23 +33,23 @@ namespace SharpCompress.Writer.Zip
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(ModificationTime.DateTimeToDosTime()), 0, 4);
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) flags), 0, 2);
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) compression), 0, 2); // zipping method
outputStream.Write(DataConverter.LittleEndian.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4);
// zipping date and time
outputStream.Write(BitConverter.GetBytes(Crc), 0, 4); // file CRC
outputStream.Write(BitConverter.GetBytes(Compressed), 0, 4); // compressed file size
outputStream.Write(BitConverter.GetBytes(Decompressed), 0, 4); // uncompressed file size
outputStream.Write(BitConverter.GetBytes((ushort) encodedFilename.Length), 0, 2); // Filename in zip
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // extra length
outputStream.Write(BitConverter.GetBytes((ushort) encodedComment.Length), 0, 2);
outputStream.Write(DataConverter.LittleEndian.GetBytes(Crc), 0, 4); // file CRC
outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 4); // compressed file size
outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 4); // uncompressed file size
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedFilename.Length), 0, 2); // Filename in zip
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // extra length
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedComment.Length), 0, 2);
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // disk=0
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // file type: binary
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // Internal file attributes
outputStream.Write(BitConverter.GetBytes((ushort) 0x8100), 0, 2);
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // disk=0
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // file type: binary
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // Internal file attributes
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0x8100), 0, 2);
// External file attributes (normal/readable)
outputStream.Write(BitConverter.GetBytes(HeaderOffset), 0, 4); // Offset of header
outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 4); // Offset of header
outputStream.Write(encodedFilename, 0, encodedFilename.Length);
outputStream.Write(encodedComment, 0, encodedComment.Length);

View File

@@ -10,6 +10,7 @@ using SharpCompress.Compressor.BZip2;
using SharpCompress.Compressor.Deflate;
using SharpCompress.Compressor.LZMA;
using SharpCompress.Compressor.PPMd;
using SharpCompress.Converter;
using SharpCompress.IO;
using DeflateStream = SharpCompress.Compressor.Deflate.DeflateStream;
@@ -74,7 +75,7 @@ namespace SharpCompress.Writer.Zip
var headersize = (uint)WriteHeader(entryPath, modificationTime, compressionInfo);
streamPosition += headersize;
return new ZipWritingStream(this, OutputStream, entry);
return new ZipWritingStream(this, OutputStream, entry, compressionInfo);
}
private string NormalizeFilename(string filename)
@@ -93,7 +94,7 @@ namespace SharpCompress.Writer.Zip
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(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
if (explicitZipCompressionInfo.Compression == ZipCompressionMethod.Deflate)
{
OutputStream.Write(new byte[] {20, 0}, 0, 2); //older version which is more compatible
@@ -111,14 +112,14 @@ namespace SharpCompress.Writer.Zip
flags |= HeaderFlags.Bit1; // eos marker
}
}
OutputStream.Write(BitConverter.GetBytes((ushort) flags), 0, 2);
OutputStream.Write(BitConverter.GetBytes((ushort)explicitZipCompressionInfo.Compression), 0, 2); // zipping method
OutputStream.Write(BitConverter.GetBytes(modificationTime.DateTimeToDosTime()), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) flags), 0, 2);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)explicitZipCompressionInfo.Compression), 0, 2); // zipping method
OutputStream.Write(DataConverter.LittleEndian.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);
// unused CRC, un/compressed size, updated later
OutputStream.Write(BitConverter.GetBytes((ushort) encodedFilename.Length), 0, 2); // filename length
OutputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // extra length
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedFilename.Length), 0, 2); // filename length
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // extra length
OutputStream.Write(encodedFilename, 0, encodedFilename.Length);
return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length;
@@ -126,9 +127,9 @@ namespace SharpCompress.Writer.Zip
private void WriteFooter(uint crc, uint compressed, uint uncompressed)
{
OutputStream.Write(BitConverter.GetBytes(crc), 0, 4);
OutputStream.Write(BitConverter.GetBytes(compressed), 0, 4);
OutputStream.Write(BitConverter.GetBytes(uncompressed), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes(crc), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes(compressed), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes(uncompressed), 0, 4);
}
private void WriteEndRecord(uint size)
@@ -136,11 +137,11 @@ namespace SharpCompress.Writer.Zip
byte[] encodedComment = ArchiveEncoding.Default.GetBytes(zipComment);
OutputStream.Write(new byte[] {80, 75, 5, 6, 0, 0, 0, 0}, 0, 8);
OutputStream.Write(BitConverter.GetBytes((ushort) entries.Count), 0, 2);
OutputStream.Write(BitConverter.GetBytes((ushort) entries.Count), 0, 2);
OutputStream.Write(BitConverter.GetBytes(size), 0, 4);
OutputStream.Write(BitConverter.GetBytes((uint) streamPosition), 0, 4);
OutputStream.Write(BitConverter.GetBytes((ushort) encodedComment.Length), 0, 2);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) entries.Count), 0, 2);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) entries.Count), 0, 2);
OutputStream.Write(DataConverter.LittleEndian.GetBytes(size), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint) streamPosition), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedComment.Length), 0, 2);
OutputStream.Write(encodedComment, 0, encodedComment.Length);
}
@@ -153,16 +154,18 @@ namespace SharpCompress.Writer.Zip
private readonly Stream originalStream;
private readonly Stream writeStream;
private readonly ZipWriter writer;
private readonly ZipCompressionInfo compressionInfo;
private CountingWritableSubStream counting;
private uint decompressed;
internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry)
internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry, CompressionInfo compressionInfo)
{
this.writer = writer;
this.originalStream = originalStream;
writeStream = GetWriteStream(originalStream);
this.writer = writer;
this.entry = entry;
this.compressionInfo = compressionInfo == null ? writer.zipCompressionInfo : new ZipCompressionInfo(compressionInfo);
writeStream = GetWriteStream(originalStream);
}
public override bool CanRead
@@ -195,7 +198,7 @@ namespace SharpCompress.Writer.Zip
{
counting = new CountingWritableSubStream(writeStream);
Stream output = counting;
switch (writer.zipCompressionInfo.Compression)
switch (compressionInfo.Compression)
{
case ZipCompressionMethod.None:
{
@@ -203,7 +206,7 @@ namespace SharpCompress.Writer.Zip
}
case ZipCompressionMethod.Deflate:
{
return new DeflateStream(counting, CompressionMode.Compress, writer.zipCompressionInfo.DeflateCompressionLevel,
return new DeflateStream(counting, CompressionMode.Compress, compressionInfo.DeflateCompressionLevel,
true);
}
case ZipCompressionMethod.BZip2:
@@ -229,7 +232,7 @@ namespace SharpCompress.Writer.Zip
}
default:
{
throw new NotSupportedException("CompressionMethod: " + writer.zipCompressionInfo.Compression);
throw new NotSupportedException("CompressionMethod: " + compressionInfo.Compression);
}
}
}
@@ -254,7 +257,7 @@ namespace SharpCompress.Writer.Zip
}
else
{
originalStream.Write(BitConverter.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4);
originalStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4);
writer.WriteFooter(entry.Crc, counting.Count, decompressed);
writer.streamPosition += entry.Compressed + 16;
}