From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs | 210 +++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs') diff --git a/Client/Assets/Scripts/XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs b/Client/Assets/Scripts/XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs new file mode 100644 index 00000000..fb6dc520 --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/Ionic/Crc/CrcCalculatorStream.cs @@ -0,0 +1,210 @@ +using System; +using System.IO; + +namespace Ionic.Crc +{ + public class CrcCalculatorStream : Stream, IDisposable + { + public long TotalBytesSlurped + { + get + { + return this._Crc32.TotalBytesRead; + } + } + + public int Crc + { + get + { + return this._Crc32.Crc32Result; + } + } + + public bool LeaveOpen + { + get + { + return this._leaveOpen; + } + set + { + this._leaveOpen = value; + } + } + + public override bool CanRead + { + get + { + return this._innerStream.CanRead; + } + } + + public override bool CanSeek + { + get + { + return false; + } + } + + public override bool CanWrite + { + get + { + return this._innerStream.CanWrite; + } + } + + public override long Length + { + get + { + bool flag = this._lengthLimit == CrcCalculatorStream.UnsetLengthLimit; + long result; + if (flag) + { + result = this._innerStream.Length; + } + else + { + result = this._lengthLimit; + } + return result; + } + } + + public override long Position + { + get + { + return this._Crc32.TotalBytesRead; + } + set + { + throw new NotSupportedException(); + } + } + + private static readonly long UnsetLengthLimit = -99L; + + internal Stream _innerStream; + + private CRC32 _Crc32; + + private long _lengthLimit = -99L; + + private bool _leaveOpen; + + public CrcCalculatorStream(Stream stream) : this(true, CrcCalculatorStream.UnsetLengthLimit, stream, null) + { + } + + public CrcCalculatorStream(Stream stream, bool leaveOpen) : this(leaveOpen, CrcCalculatorStream.UnsetLengthLimit, stream, null) + { + } + + public CrcCalculatorStream(Stream stream, long length) : this(true, length, stream, null) + { + bool flag = length < 0L; + if (flag) + { + throw new ArgumentException("length"); + } + } + + public CrcCalculatorStream(Stream stream, long length, bool leaveOpen) : this(leaveOpen, length, stream, null) + { + bool flag = length < 0L; + if (flag) + { + throw new ArgumentException("length"); + } + } + + public CrcCalculatorStream(Stream stream, long length, bool leaveOpen, CRC32 crc32) : this(leaveOpen, length, stream, crc32) + { + bool flag = length < 0L; + if (flag) + { + throw new ArgumentException("length"); + } + } + + private CrcCalculatorStream(bool leaveOpen, long length, Stream stream, CRC32 crc32) + { + this._innerStream = stream; + this._Crc32 = (crc32 ?? new CRC32()); + this._lengthLimit = length; + this._leaveOpen = leaveOpen; + } + + public override int Read(byte[] buffer, int offset, int count) + { + int count2 = count; + bool flag = this._lengthLimit != CrcCalculatorStream.UnsetLengthLimit; + if (flag) + { + bool flag2 = this._Crc32.TotalBytesRead >= this._lengthLimit; + if (flag2) + { + return 0; + } + long num = this._lengthLimit - this._Crc32.TotalBytesRead; + bool flag3 = num < (long)count; + if (flag3) + { + count2 = (int)num; + } + } + int num2 = this._innerStream.Read(buffer, offset, count2); + bool flag4 = num2 > 0; + if (flag4) + { + this._Crc32.SlurpBlock(buffer, offset, num2); + } + return num2; + } + + public override void Write(byte[] buffer, int offset, int count) + { + bool flag = count > 0; + if (flag) + { + this._Crc32.SlurpBlock(buffer, offset, count); + } + this._innerStream.Write(buffer, offset, count); + } + + public override void Flush() + { + this._innerStream.Flush(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + void IDisposable.Dispose() + { + this.Close(); + } + + public override void Close() + { + base.Close(); + bool flag = !this._leaveOpen; + if (flag) + { + this._innerStream.Close(); + } + } + } +} -- cgit v1.1-26-g67d0