public TarOutputStream(Stream outputStream, int blockFactor) { if (outputStream == null) { throw new ArgumentNullException(nameof(outputStream)); } this._outputStream = outputStream; _buffer = TarBuffer.CreateOutputTarBuffer(outputStream, blockFactor); _assemblyBuffer = new byte[0x200]; _blockBuffer = new byte[0x200]; }
public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockFactor) { if (inputStream == null) { throw new ArgumentNullException(nameof(inputStream)); } if (blockFactor <= 0) { throw new ArgumentOutOfRangeException(nameof(blockFactor), "Factor cannot be negative"); } TarBuffer buffer = new TarBuffer { _inputStream = inputStream, _outputStream = null }; buffer.Initialize(blockFactor); return buffer; }
public TarEntry GetNextEntry() { if (_hasHitEof) { return(null); } if (_currentEntry != null) { SkipToNextEntry(); } byte[] block = _tarBuffer.ReadBlock(); if (block == null) { _hasHitEof = true; } else if (TarBuffer.IsEndOfArchiveBlock(block)) { _hasHitEof = true; } if (_hasHitEof) { _currentEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(block); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } _entryOffset = 0L; _entrySize = header.Size; StringBuilder builder = null; if (header.TypeFlag == 0x4c) { byte[] buffer = new byte[0x200]; long size = _entrySize; builder = new StringBuilder(); while (size > 0L) { int length = Read(buffer, 0, (size > buffer.Length) ? buffer.Length : ((int)size)); if (length == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } builder.Append(TarHeader.ParseName(buffer, 0, length)); size -= length; } SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x67) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 120) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x56) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (((header.TypeFlag != 0x30) && (header.TypeFlag != 0)) && (header.TypeFlag != 0x35)) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } if (_entryFactory == null) { _currentEntry = new TarEntry(block); if (builder != null) { _currentEntry.Name = builder.ToString(); } } else { _currentEntry = _entryFactory.CreateEntry(block); } _entryOffset = 0L; _entrySize = _currentEntry.Size; } catch (InvalidHeaderException exception) { _entrySize = 0L; _entryOffset = 0L; _currentEntry = null; throw new InvalidHeaderException(string.Format("Bad header in record {0} block {1} {2}", _tarBuffer.CurrentRecord, _tarBuffer.CurrentBlock, exception.Message)); } } return(_currentEntry); }
public TarInputStream(Stream inputStream, int blockFactor) { _inputStream = inputStream; _tarBuffer = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor); }