161 lines
4.0 KiB
C#
161 lines
4.0 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace ICSharpCode.SharpZipLib.Core
|
|
{
|
|
// Token: 0x0200001E RID: 30
|
|
public sealed class StreamUtils
|
|
{
|
|
// Token: 0x060000D8 RID: 216 RVA: 0x00007734 File Offset: 0x00006734
|
|
public static void ReadFully(Stream stream, byte[] buffer)
|
|
{
|
|
StreamUtils.ReadFully(stream, buffer, 0, buffer.Length);
|
|
}
|
|
|
|
// Token: 0x060000D9 RID: 217 RVA: 0x00007744 File Offset: 0x00006744
|
|
public static void ReadFully(Stream stream, byte[] buffer, int offset, int count)
|
|
{
|
|
if (stream == null)
|
|
{
|
|
throw new ArgumentNullException("stream");
|
|
}
|
|
if (buffer == null)
|
|
{
|
|
throw new ArgumentNullException("buffer");
|
|
}
|
|
if (offset < 0 || offset > buffer.Length)
|
|
{
|
|
throw new ArgumentOutOfRangeException("offset");
|
|
}
|
|
if (count < 0 || offset + count > buffer.Length)
|
|
{
|
|
throw new ArgumentOutOfRangeException("count");
|
|
}
|
|
while (count > 0)
|
|
{
|
|
int num = stream.Read(buffer, offset, count);
|
|
if (num <= 0)
|
|
{
|
|
throw new EndOfStreamException();
|
|
}
|
|
offset += num;
|
|
count -= num;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000DA RID: 218 RVA: 0x000077BC File Offset: 0x000067BC
|
|
public static void Copy(Stream source, Stream destination, byte[] buffer)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new ArgumentNullException("source");
|
|
}
|
|
if (destination == null)
|
|
{
|
|
throw new ArgumentNullException("destination");
|
|
}
|
|
if (buffer == null)
|
|
{
|
|
throw new ArgumentNullException("buffer");
|
|
}
|
|
if (buffer.Length < 128)
|
|
{
|
|
throw new ArgumentException("Buffer is too small", "buffer");
|
|
}
|
|
bool flag = true;
|
|
while (flag)
|
|
{
|
|
int num = source.Read(buffer, 0, buffer.Length);
|
|
if (num > 0)
|
|
{
|
|
destination.Write(buffer, 0, num);
|
|
}
|
|
else
|
|
{
|
|
destination.Flush();
|
|
flag = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000DB RID: 219 RVA: 0x00007837 File Offset: 0x00006837
|
|
public static void Copy(Stream source, Stream destination, byte[] buffer, ProgressHandler progressHandler, TimeSpan updateInterval, object sender, string name)
|
|
{
|
|
StreamUtils.Copy(source, destination, buffer, progressHandler, updateInterval, sender, name, -1L);
|
|
}
|
|
|
|
// Token: 0x060000DC RID: 220 RVA: 0x0000784C File Offset: 0x0000684C
|
|
public static void Copy(Stream source, Stream destination, byte[] buffer, ProgressHandler progressHandler, TimeSpan updateInterval, object sender, string name, long fixedTarget)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new ArgumentNullException("source");
|
|
}
|
|
if (destination == null)
|
|
{
|
|
throw new ArgumentNullException("destination");
|
|
}
|
|
if (buffer == null)
|
|
{
|
|
throw new ArgumentNullException("buffer");
|
|
}
|
|
if (buffer.Length < 128)
|
|
{
|
|
throw new ArgumentException("Buffer is too small", "buffer");
|
|
}
|
|
if (progressHandler == null)
|
|
{
|
|
throw new ArgumentNullException("progressHandler");
|
|
}
|
|
bool flag = true;
|
|
DateTime dateTime = DateTime.Now;
|
|
long num = 0L;
|
|
long num2 = 0L;
|
|
if (fixedTarget >= 0L)
|
|
{
|
|
num2 = fixedTarget;
|
|
}
|
|
else if (source.CanSeek)
|
|
{
|
|
num2 = source.Length - source.Position;
|
|
}
|
|
ProgressEventArgs progressEventArgs = new ProgressEventArgs(name, num, num2);
|
|
progressHandler(sender, progressEventArgs);
|
|
bool flag2 = true;
|
|
while (flag)
|
|
{
|
|
int num3 = source.Read(buffer, 0, buffer.Length);
|
|
if (num3 > 0)
|
|
{
|
|
num += (long)num3;
|
|
flag2 = false;
|
|
destination.Write(buffer, 0, num3);
|
|
}
|
|
else
|
|
{
|
|
destination.Flush();
|
|
flag = false;
|
|
}
|
|
if (DateTime.Now - dateTime > updateInterval)
|
|
{
|
|
flag2 = true;
|
|
dateTime = DateTime.Now;
|
|
progressEventArgs = new ProgressEventArgs(name, num, num2);
|
|
progressHandler(sender, progressEventArgs);
|
|
flag = progressEventArgs.ContinueRunning;
|
|
}
|
|
}
|
|
if (!flag2)
|
|
{
|
|
progressEventArgs = new ProgressEventArgs(name, num, num2);
|
|
progressHandler(sender, progressEventArgs);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000DD RID: 221 RVA: 0x00007979 File Offset: 0x00006979
|
|
private StreamUtils()
|
|
{
|
|
}
|
|
}
|
|
}
|