Skip to content

Commit 9022ac3

Browse files
committed
1 parent f40e24e commit 9022ac3

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace ICSharpCode.SharpZipLib.Core
4+
{
5+
internal static class Empty
6+
{
7+
#if NET45
8+
internal static class EmptyArray<T>
9+
{
10+
public static readonly T[] Value = new T[0];
11+
}
12+
13+
public static T[] Array<T>() => EmptyArray<T>.Value;
14+
#else
15+
public static T[] Array<T>() => System.Array.Empty<T>();
16+
#endif
17+
}
18+
}

src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using ICSharpCode.SharpZipLib.Core;
2+
13
using System;
24
using System.Security.Cryptography;
35

@@ -159,11 +161,9 @@ public byte[] GetAuthCode()
159161
/// </summary>
160162
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
161163
{
162-
if (inputCount > 0)
163-
{
164-
throw new NotImplementedException("TransformFinalBlock is not implemented and inputCount is greater than 0");
165-
}
166-
return Array.Empty<byte>();
164+
return inputCount > 0
165+
? throw new NotImplementedException("TransformFinalBlock is not implemented and inputCount is greater than 0")
166+
: Empty.Array<byte>();
167167
}
168168

169169
/// <summary>

src/ICSharpCode.SharpZipLib/Tar/TarEntry.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using ICSharpCode.SharpZipLib.Core;
2+
13
using System;
24
using System.IO;
35
using System.Text;
@@ -399,7 +401,7 @@ public void GetFileTarHeader(TarHeader header, string file)
399401
public TarEntry[] GetDirectoryEntries()
400402
{
401403
if ((file == null) || !Directory.Exists(file))
402-
return Array.Empty<TarEntry>();
404+
return Empty.Array<TarEntry>();
403405

404406
string[] list = Directory.GetFileSystemEntries(file);
405407
TarEntry[] result = new TarEntry[list.Length];

src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using ICSharpCode.SharpZipLib.Core;
2+
13
using System;
24
using System.IO;
35

@@ -517,7 +519,7 @@ public ZipExtraData(byte[] data)
517519
{
518520
if (data == null)
519521
{
520-
_data = Array.Empty<byte>();
522+
_data = Empty.Array<byte>();
521523
}
522524
else
523525
{
@@ -548,7 +550,7 @@ public void Clear()
548550
{
549551
if ((_data == null) || (_data.Length != 0))
550552
{
551-
_data = Array.Empty<byte>();
553+
_data = Empty.Array<byte>();
552554
}
553555
}
554556

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ public ZipFile(Stream stream, bool leaveOpen)
530530
}
531531
else
532532
{
533-
entries_ = Array.Empty<ZipEntry>();
533+
entries_ = Empty.Array<ZipEntry>();
534534
isNewArchive_ = true;
535535
}
536536
}
@@ -540,7 +540,7 @@ public ZipFile(Stream stream, bool leaveOpen)
540540
/// </summary>
541541
internal ZipFile()
542542
{
543-
entries_ = Array.Empty<ZipEntry>();
543+
entries_ = Empty.Array<ZipEntry>();
544544
isNewArchive_ = true;
545545
}
546546

@@ -2325,7 +2325,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry)
23252325
baseStream_.Write(centralExtraData, 0, centralExtraData.Length);
23262326
}
23272327

2328-
byte[] rawComment = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : Array.Empty<byte>();
2328+
byte[] rawComment = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : Empty.Array<byte>();
23292329

23302330
if (rawComment.Length > 0)
23312331
{
@@ -3232,7 +3232,7 @@ private void DisposeInternal(bool disposing)
32323232
if (!isDisposed_)
32333233
{
32343234
isDisposed_ = true;
3235-
entries_ = Array.Empty<ZipEntry>();
3235+
entries_ = Empty.Array<ZipEntry>();
32363236

32373237
if (IsStreamOwner && (baseStream_ != null))
32383238
{

src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ public override void Finish()
861861
byte[] entryComment =
862862
(entry.Comment != null) ?
863863
ZipStrings.ConvertToArray(entry.Flags, entry.Comment) :
864-
Array.Empty<byte>();
864+
Empty.Array<byte>();
865865

866866
if (entryComment.Length > 0xffff)
867867
{
@@ -976,7 +976,7 @@ public override void Flush()
976976
/// <summary>
977977
/// Comment for the entire archive recorded in central header.
978978
/// </summary>
979-
private byte[] zipComment = Array.Empty<byte>();
979+
private byte[] zipComment = Empty.Array<byte>();
980980

981981
/// <summary>
982982
/// Flag indicating that header patching is required for the current entry.

src/ICSharpCode.SharpZipLib/Zip/ZipStrings.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using ICSharpCode.SharpZipLib.Core;
2+
3+
using System;
24
using System.Text;
35

46
namespace ICSharpCode.SharpZipLib.Zip
@@ -174,7 +176,7 @@ public static string ConvertToStringExt(int flags, byte[] data)
174176
/// <returns>Converted array</returns>
175177
public static byte[] ConvertToArray(string str)
176178
=> str == null
177-
? Array.Empty<byte>()
179+
? Empty.Array<byte>()
178180
: Encoding.GetEncoding(CodePage).GetBytes(str);
179181

180182
/// <summary>
@@ -187,7 +189,7 @@ public static byte[] ConvertToArray(string str)
187189
/// <returns>Converted array</returns>
188190
public static byte[] ConvertToArray(int flags, string str)
189191
=> (string.IsNullOrEmpty(str))
190-
? Array.Empty<byte>()
192+
? Empty.Array<byte>()
191193
: EncodingFromFlag(flags).GetBytes(str);
192194
}
193195
}

0 commit comments

Comments
 (0)