You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
committed by
Jo Shields
parent
183bba2c9a
commit
6992685b86
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user