From abddabf18e5402ac37ebaebc3d6a880a14aacfe8 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sun, 29 Apr 2018 16:27:26 +0100 Subject: [PATCH] Proper fixes for all platforms --- src/SharpCompress/Common/ArchiveEncoding.cs | 17 +++++++++++++++++ .../Common/Zip/Headers/DirectoryEntryHeader.cs | 12 ++++++------ .../Common/Zip/Headers/LocalEntryHeader.cs | 3 +-- src/SharpCompress/SharpCompress.csproj | 8 +++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs index e37da084..a8712115 100644 --- a/src/SharpCompress/Common/ArchiveEncoding.cs +++ b/src/SharpCompress/Common/ArchiveEncoding.cs @@ -32,11 +32,28 @@ namespace SharpCompress.Common Password = Encoding.UTF8; } +#if NETSTANDARD1_3 || NETSTANDARD2_0 + static ArchiveEncoding() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + } +#endif + public string Decode(byte[] bytes) { return Decode(bytes, 0, bytes.Length); } + public string Decode437(byte[] bytes) + { +#if NETSTANDARD1_0 + return Decode(bytes, 0, bytes.Length); +#else + var extendedASCIIEncoding = Encoding.GetEncoding(437); + return extendedASCIIEncoding.GetString(bytes, 0, bytes.Length); +#endif + } + public string Decode(byte[] bytes, int start, int length) { return GetDecoder().Invoke(bytes, start, length); diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs index 6c855a28..5e32020d 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Linq; using System.Text; @@ -34,12 +33,11 @@ namespace SharpCompress.Common.Zip.Headers byte[] name = reader.ReadBytes(nameLength); byte[] extra = reader.ReadBytes(extraLength); byte[] comment = reader.ReadBytes(commentLength); + if ((Flags & HeaderFlags.UTF8) == 0) { - // Use IBM Code Page 437 (IBM PC character encoding set) - var extendedASCIIEncoding = Encoding.GetEncoding("IBM437"); - Name = extendedASCIIEncoding.GetString(name, 0, name.Length); - Comment = extendedASCIIEncoding.GetString(comment, 0, comment.Length); + Name = ArchiveEncoding.Decode437(name); + Comment = ArchiveEncoding.Decode437(comment); } else { @@ -62,10 +60,12 @@ namespace SharpCompress.Common.Zip.Headers { CompressedSize = zip64ExtraData.CompressedSize; } + if (UncompressedSize == uint.MaxValue) { UncompressedSize = zip64ExtraData.UncompressedSize; } + if (RelativeOffsetOfEntryHeader == uint.MaxValue) { RelativeOffsetOfEntryHeader = zip64ExtraData.RelativeOffsetOfEntryHeader; diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs index 01f3a63e..582d04f7 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs @@ -28,8 +28,7 @@ namespace SharpCompress.Common.Zip.Headers if ((Flags & HeaderFlags.UTF8) == 0) { // Use IBM Code Page 437 (IBM PC character encoding set) - var extendedASCIIEncoding = Encoding.GetEncoding("IBM437"); - Name = extendedASCIIEncoding.GetString(name, 0, name.Length); + Name = ArchiveEncoding.Decode437(name); } else { diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index 5c1d0815..58cf4dd3 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -19,7 +19,7 @@ https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt false false - SharpCompress is a compression library for NET Standard 1.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. + SharpCompress is a compression library for NET Standard 1.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. $(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT @@ -27,7 +27,13 @@ $(DefineConstants);NETCORE + + + $(DefineConstants);NETCORE + + + \ No newline at end of file