using System; using System.IO; namespace ICSharpCode.SharpZipLib.Tar { // Token: 0x02000035 RID: 53 public class TarBuffer { // Token: 0x17000053 RID: 83 // (get) Token: 0x060001A3 RID: 419 RVA: 0x0000A39C File Offset: 0x0000939C public int RecordSize { get { return this.recordSize; } } // Token: 0x060001A4 RID: 420 RVA: 0x0000A3A4 File Offset: 0x000093A4 [Obsolete("Use RecordSize property instead")] public int GetRecordSize() { return this.recordSize; } // Token: 0x17000054 RID: 84 // (get) Token: 0x060001A5 RID: 421 RVA: 0x0000A3AC File Offset: 0x000093AC public int BlockFactor { get { return this.blockFactor; } } // Token: 0x060001A6 RID: 422 RVA: 0x0000A3B4 File Offset: 0x000093B4 [Obsolete("Use BlockFactor property instead")] public int GetBlockFactor() { return this.blockFactor; } // Token: 0x060001A7 RID: 423 RVA: 0x0000A3BC File Offset: 0x000093BC protected TarBuffer() { } // Token: 0x060001A8 RID: 424 RVA: 0x0000A3DE File Offset: 0x000093DE public static TarBuffer CreateInputTarBuffer(Stream inputStream) { if (inputStream == null) { throw new ArgumentNullException("inputStream"); } return TarBuffer.CreateInputTarBuffer(inputStream, 20); } // Token: 0x060001A9 RID: 425 RVA: 0x0000A3F8 File Offset: 0x000093F8 public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockFactor) { if (inputStream == null) { throw new ArgumentNullException("inputStream"); } if (blockFactor <= 0) { throw new ArgumentOutOfRangeException("blockFactor", "Factor cannot be negative"); } TarBuffer tarBuffer = new TarBuffer(); tarBuffer.inputStream = inputStream; tarBuffer.outputStream = null; tarBuffer.Initialize(blockFactor); return tarBuffer; } // Token: 0x060001AA RID: 426 RVA: 0x0000A443 File Offset: 0x00009443 public static TarBuffer CreateOutputTarBuffer(Stream outputStream) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } return TarBuffer.CreateOutputTarBuffer(outputStream, 20); } // Token: 0x060001AB RID: 427 RVA: 0x0000A45C File Offset: 0x0000945C public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (blockFactor <= 0) { throw new ArgumentOutOfRangeException("blockFactor", "Factor cannot be negative"); } TarBuffer tarBuffer = new TarBuffer(); tarBuffer.inputStream = null; tarBuffer.outputStream = outputStream; tarBuffer.Initialize(blockFactor); return tarBuffer; } // Token: 0x060001AC RID: 428 RVA: 0x0000A4A8 File Offset: 0x000094A8 private void Initialize(int archiveBlockFactor) { this.blockFactor = archiveBlockFactor; this.recordSize = archiveBlockFactor * 512; this.recordBuffer = new byte[this.RecordSize]; if (this.inputStream != null) { this.currentRecordIndex = -1; this.currentBlockIndex = this.BlockFactor; return; } this.currentRecordIndex = 0; this.currentBlockIndex = 0; } // Token: 0x060001AD RID: 429 RVA: 0x0000A504 File Offset: 0x00009504 [Obsolete("Use IsEndOfArchiveBlock instead")] public bool IsEOFBlock(byte[] block) { if (block == null) { throw new ArgumentNullException("block"); } if (block.Length != 512) { throw new ArgumentException("block length is invalid"); } for (int i = 0; i < 512; i++) { if (block[i] != 0) { return false; } } return true; } // Token: 0x060001AE RID: 430 RVA: 0x0000A54C File Offset: 0x0000954C public static bool IsEndOfArchiveBlock(byte[] block) { if (block == null) { throw new ArgumentNullException("block"); } if (block.Length != 512) { throw new ArgumentException("block length is invalid"); } for (int i = 0; i < 512; i++) { if (block[i] != 0) { return false; } } return true; } // Token: 0x060001AF RID: 431 RVA: 0x0000A594 File Offset: 0x00009594 public void SkipBlock() { if (this.inputStream == null) { throw new TarException("no input stream defined"); } if (this.currentBlockIndex >= this.BlockFactor && !this.ReadRecord()) { throw new TarException("Failed to read a record"); } this.currentBlockIndex++; } // Token: 0x060001B0 RID: 432 RVA: 0x0000A5E4 File Offset: 0x000095E4 public byte[] ReadBlock() { if (this.inputStream == null) { throw new TarException("TarBuffer.ReadBlock - no input stream defined"); } if (this.currentBlockIndex >= this.BlockFactor && !this.ReadRecord()) { throw new TarException("Failed to read a record"); } byte[] array = new byte[512]; Array.Copy(this.recordBuffer, this.currentBlockIndex * 512, array, 0, 512); this.currentBlockIndex++; return array; } // Token: 0x060001B1 RID: 433 RVA: 0x0000A660 File Offset: 0x00009660 private bool ReadRecord() { if (this.inputStream == null) { throw new TarException("no input stream stream defined"); } this.currentBlockIndex = 0; int num = 0; long num2; for (int i = this.RecordSize; i > 0; i -= (int)num2) { num2 = (long)this.inputStream.Read(this.recordBuffer, num, i); if (num2 <= 0L) { break; } num += (int)num2; } this.currentRecordIndex++; return true; } // Token: 0x17000055 RID: 85 // (get) Token: 0x060001B2 RID: 434 RVA: 0x0000A6C9 File Offset: 0x000096C9 public int CurrentBlock { get { return this.currentBlockIndex; } } // Token: 0x17000056 RID: 86 // (get) Token: 0x060001B3 RID: 435 RVA: 0x0000A6D1 File Offset: 0x000096D1 // (set) Token: 0x060001B4 RID: 436 RVA: 0x0000A6D9 File Offset: 0x000096D9 public bool IsStreamOwner { get { return this.isStreamOwner_; } set { this.isStreamOwner_ = value; } } // Token: 0x060001B5 RID: 437 RVA: 0x0000A6E2 File Offset: 0x000096E2 [Obsolete("Use CurrentBlock property instead")] public int GetCurrentBlockNum() { return this.currentBlockIndex; } // Token: 0x17000057 RID: 87 // (get) Token: 0x060001B6 RID: 438 RVA: 0x0000A6EA File Offset: 0x000096EA public int CurrentRecord { get { return this.currentRecordIndex; } } // Token: 0x060001B7 RID: 439 RVA: 0x0000A6F2 File Offset: 0x000096F2 [Obsolete("Use CurrentRecord property instead")] public int GetCurrentRecordNum() { return this.currentRecordIndex; } // Token: 0x060001B8 RID: 440 RVA: 0x0000A6FC File Offset: 0x000096FC public void WriteBlock(byte[] block) { if (block == null) { throw new ArgumentNullException("block"); } if (this.outputStream == null) { throw new TarException("TarBuffer.WriteBlock - no output stream defined"); } if (block.Length != 512) { string text = string.Format("TarBuffer.WriteBlock - block to write has length '{0}' which is not the block size of '{1}'", block.Length, 512); throw new TarException(text); } if (this.currentBlockIndex >= this.BlockFactor) { this.WriteRecord(); } Array.Copy(block, 0, this.recordBuffer, this.currentBlockIndex * 512, 512); this.currentBlockIndex++; } // Token: 0x060001B9 RID: 441 RVA: 0x0000A798 File Offset: 0x00009798 public void WriteBlock(byte[] buffer, int offset) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (this.outputStream == null) { throw new TarException("TarBuffer.WriteBlock - no output stream stream defined"); } if (offset < 0 || offset >= buffer.Length) { throw new ArgumentOutOfRangeException("offset"); } if (offset + 512 > buffer.Length) { string text = string.Format("TarBuffer.WriteBlock - record has length '{0}' with offset '{1}' which is less than the record size of '{2}'", buffer.Length, offset, this.recordSize); throw new TarException(text); } if (this.currentBlockIndex >= this.BlockFactor) { this.WriteRecord(); } Array.Copy(buffer, offset, this.recordBuffer, this.currentBlockIndex * 512, 512); this.currentBlockIndex++; } // Token: 0x060001BA RID: 442 RVA: 0x0000A854 File Offset: 0x00009854 private void WriteRecord() { if (this.outputStream == null) { throw new TarException("TarBuffer.WriteRecord no output stream defined"); } this.outputStream.Write(this.recordBuffer, 0, this.RecordSize); this.outputStream.Flush(); this.currentBlockIndex = 0; this.currentRecordIndex++; } // Token: 0x060001BB RID: 443 RVA: 0x0000A8AC File Offset: 0x000098AC private void WriteFinalRecord() { if (this.outputStream == null) { throw new TarException("TarBuffer.WriteFinalRecord no output stream defined"); } if (this.currentBlockIndex > 0) { int num = this.currentBlockIndex * 512; Array.Clear(this.recordBuffer, num, this.RecordSize - num); this.WriteRecord(); } this.outputStream.Flush(); } // Token: 0x060001BC RID: 444 RVA: 0x0000A908 File Offset: 0x00009908 public void Close() { if (this.outputStream != null) { this.WriteFinalRecord(); if (this.isStreamOwner_) { this.outputStream.Close(); } this.outputStream = null; return; } if (this.inputStream != null) { if (this.isStreamOwner_) { this.inputStream.Close(); } this.inputStream = null; } } // Token: 0x040000ED RID: 237 public const int BlockSize = 512; // Token: 0x040000EE RID: 238 public const int DefaultBlockFactor = 20; // Token: 0x040000EF RID: 239 public const int DefaultRecordSize = 10240; // Token: 0x040000F0 RID: 240 private Stream inputStream; // Token: 0x040000F1 RID: 241 private Stream outputStream; // Token: 0x040000F2 RID: 242 private byte[] recordBuffer; // Token: 0x040000F3 RID: 243 private int currentBlockIndex; // Token: 0x040000F4 RID: 244 private int currentRecordIndex; // Token: 0x040000F5 RID: 245 private int recordSize = 10240; // Token: 0x040000F6 RID: 246 private int blockFactor = 20; // Token: 0x040000F7 RID: 247 private bool isStreamOwner_ = true; } }