- Initial commit
This commit is contained in:
50
Runtime/3rdParty/BouncyCastle/util/io/compression/ZLib.cs
vendored
Normal file
50
Runtime/3rdParty/BouncyCastle/util/io/compression/ZLib.cs
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System.IO;
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.IO.Compression;
|
||||
#else
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
|
||||
#endif
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO.Compression
|
||||
{
|
||||
internal static class ZLib
|
||||
{
|
||||
internal static Stream CompressOutput(Stream stream, int zlibCompressionLevel, bool leaveOpen = false)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return new ZLibStream(stream, GetCompressionLevel(zlibCompressionLevel), leaveOpen);
|
||||
#else
|
||||
return leaveOpen
|
||||
? new ZOutputStreamLeaveOpen(stream, zlibCompressionLevel, false)
|
||||
: new ZOutputStream(stream, zlibCompressionLevel, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static Stream DecompressInput(Stream stream)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return new ZLibStream(stream, CompressionMode.Decompress, leaveOpen: false);
|
||||
#else
|
||||
return new ZInputStream(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
internal static CompressionLevel GetCompressionLevel(int zlibCompressionLevel)
|
||||
{
|
||||
return zlibCompressionLevel switch
|
||||
{
|
||||
0 => CompressionLevel.NoCompression,
|
||||
1 or 2 or 3 => CompressionLevel.Fastest,
|
||||
7 or 8 or 9 => CompressionLevel.SmallestSize,
|
||||
_ => CompressionLevel.Optimal,
|
||||
};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
Reference in New Issue
Block a user