Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -3,7 +3,8 @@ SUBDIRS =
include ../../build/rules.make
LIBRARY = System.IO.Compression.dll
LIB_MCS_FLAGS = /r:System /r:System.Core /unsafe
LIB_REFS = System System.Core
LIB_MCS_FLAGS = /unsafe
TEST_MCS_FLAGS = /r:System /r:System.Core
include ../../build/library.make

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SharpCompress.Common;
namespace SharpCompress.Archive
@@ -105,11 +106,11 @@ namespace SharpCompress.Archive
return false;
}
public void SaveTo(Stream stream, CompressionInfo compressionType)
public void SaveTo(Stream stream, CompressionInfo compressionType, Encoding encoding = null)
{
//reset streams of new entries
newEntries.Cast<IWritableArchiveEntry>().ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin));
SaveTo(stream, compressionType, OldEntries, newEntries);
SaveTo(stream, compressionType, encoding ?? ArchiveEncoding.Default, OldEntries, newEntries);
}
protected TEntry CreateEntry(string key, Stream source, long size, DateTime? modified,
@@ -125,7 +126,7 @@ namespace SharpCompress.Archive
protected abstract TEntry CreateEntryInternal(string key, Stream source, long size, DateTime? modified,
bool closeStream);
protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
protected abstract void SaveTo(Stream stream, CompressionInfo compressionType, Encoding encoding,
IEnumerable<TEntry> oldEntries, IEnumerable<TEntry> newEntries);
public override void Dispose()

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SharpCompress.Common;
using SharpCompress.Common.Zip;
using SharpCompress.Common.Zip.Headers;
@@ -205,13 +206,13 @@ namespace SharpCompress.Archive.Zip
}
}
}
}
}
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo, Encoding encoding,
IEnumerable<ZipArchiveEntry> oldEntries,
IEnumerable<ZipArchiveEntry> newEntries)
{
using (var writer = new ZipWriter(stream, compressionInfo, string.Empty))
using (var writer = new ZipWriter(stream, compressionInfo, string.Empty, encoding))
{
foreach (var entry in oldEntries.Concat(newEntries)
.Where(x => !x.IsDirectory))

View File

@@ -66,6 +66,9 @@ namespace SharpCompress.Common.Zip.Headers
protected void LoadExtra(byte[] extra)
{
if (extra.Length % 2 != 0)
return;
for (int i = 0; i < extra.Length;)
{
ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);

View File

@@ -30,16 +30,18 @@ namespace SharpCompress.Writer.Zip
private readonly List<ZipCentralDirectoryEntry> entries = new List<ZipCentralDirectoryEntry>();
private readonly string zipComment;
private readonly Encoding encoding;
private long streamPosition;
#if PPMd
private readonly PpmdProperties ppmdProperties; // Caching properties to speed up PPMd.
#endif
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment)
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment, Encoding encoding = null)
: base(ArchiveType.Zip)
{
this.zipComment = zipComment ?? string.Empty;
this.encoding = encoding ?? ArchiveEncoding.Default;
switch (compressionInfo.Type)
{
@@ -137,11 +139,11 @@ namespace SharpCompress.Writer.Zip
private int WriteHeader(string filename, DateTime? modificationTime)
{
byte[] encodedFilename = Encoding.UTF8.GetBytes(filename);
byte[] encodedFilename = encoding.GetBytes(filename);
OutputStream.Write(BitConverter.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version
HeaderFlags flags = HeaderFlags.UTF8;
HeaderFlags flags = encoding == Encoding.UTF8 ? HeaderFlags.UTF8 : (HeaderFlags)0;
if (!OutputStream.CanSeek)
{
flags |= HeaderFlags.UsePostDataDescriptor;
@@ -172,7 +174,7 @@ namespace SharpCompress.Writer.Zip
private void WriteEndRecord(uint size)
{
byte[] encodedComment = Encoding.UTF8.GetBytes(zipComment);
byte[] encodedComment = encoding.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);

View File

@@ -106,8 +106,8 @@ namespace System.IO.Compression
zipFile = mode == ZipArchiveMode.Create ?
SharpCompress.Archive.Zip.ZipArchive.Create() :
SharpCompress.Archive.Zip.ZipArchive.Open(stream);
} catch (Exception) {
throw new InvalidDataException("The contents of the stream are not in the zip archive format.");
} catch (Exception e) {
throw new InvalidDataException("The contents of the stream are not in the zip archive format.", e);
}
entries = new Dictionary<string, ZipArchiveEntry>();
@@ -202,7 +202,7 @@ namespace System.IO.Compression
private void Save()
{
using (var newZip = new MemoryStream()) {
zipFile.SaveTo(newZip, CompressionType.Deflate);
zipFile.SaveTo(newZip, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8);
stream.SetLength(0);
stream.Position = 0;