public void PutNextEntry(TarEntry entry) { if (entry.TarHeader.name.Length > TarHeader.NAMELEN) { throw new InvalidHeaderException(string.Concat(new object[] { "file name '", entry.TarHeader.name, "' is too long ( > ", TarHeader.NAMELEN, " bytes )" })); } entry.WriteEntryHeader(this.recordBuf); this.buffer.WriteRecord(this.recordBuf); this.currBytes = 0; this.currSize = entry.IsDirectory ? 0 : ((int) entry.Size); }
public void WriteEntry(TarEntry entry, bool recurse) { string path = null; string file = entry.File; if ((file == null) || (file.Length == 0)) { entry = TarEntry.CreateTarEntry(entry.Name); } else { string name = entry.Name; entry = TarEntry.CreateEntryFromFile(file); entry.Name = name; } if (this.verbose) { this.OnProgressMessageEvent(entry.Name); } if ((this.asciiTranslate && !entry.IsDirectory) && !this.IsBinary(file)) { path = Path.GetTempFileName(); StreamReader reader = File.OpenText(file); Stream stream = new BufferedStream(File.Create(path)); while (true) { string s = reader.ReadLine(); if (s == null) { break; } byte[] bytes = Encoding.ASCII.GetBytes(s); stream.Write(bytes, 0, bytes.Length); stream.WriteByte(10); } reader.Close(); stream.Flush(); stream.Close(); entry.Size = new FileInfo(path).Length; file = path; } string str5 = null; if ((this.rootPath != null) && entry.Name.StartsWith(this.rootPath)) { str5 = entry.Name.Substring(this.rootPath.Length + 1); } if (this.pathPrefix != null) { str5 = (str5 == null) ? (this.pathPrefix + "/" + entry.Name) : (this.pathPrefix + "/" + str5); } if (str5 != null) { entry.Name = str5; } this.tarOut.PutNextEntry(entry); if (entry.IsDirectory) { if (recurse) { TarEntry[] directoryEntries = entry.GetDirectoryEntries(); for (int i = 0; i < directoryEntries.Length; i++) { this.WriteEntry(directoryEntries[i], recurse); } } } else { Stream stream2 = File.OpenRead(file); int num2 = 0; byte[] buffer = new byte[0x8000]; while (true) { int count = stream2.Read(buffer, 0, buffer.Length); if (count <= 0) { break; } this.tarOut.Write(buffer, 0, count); num2 += count; } Console.WriteLine("written " + num2 + " bytes"); stream2.Close(); if ((path != null) && (path.Length > 0)) { File.Delete(path); } this.tarOut.CloseEntry(); } }
private void ExtractEntry(string destDir, TarEntry entry) { int num; if (this.verbose) { this.OnProgressMessageEvent(entry.Name); } string str = entry.Name.Replace('/', Path.DirectorySeparatorChar); if (!destDir.EndsWith(Path.DirectorySeparatorChar.ToString())) { destDir = destDir + Path.DirectorySeparatorChar; } string directoryName = destDir + str; if (entry.IsDirectory) { this.EnsureDirectoryExists(directoryName); return; } string str3 = Path.GetDirectoryName(directoryName); this.EnsureDirectoryExists(str3); if (this.keepOldFiles && File.Exists(directoryName)) { if (this.verbose) { this.OnProgressMessageEvent("not overwriting " + entry.Name); } return; } bool flag = false; Stream stream = File.Create(directoryName); if (this.asciiTranslate) { flag = !this.IsBinary(directoryName); } StreamWriter writer = null; if (flag) { writer = new StreamWriter(stream); } byte[] buffer = new byte[0x8000]; Label_00E8: num = this.tarIn.Read(buffer, 0, buffer.Length); if (num > 0) { if (flag) { int index = 0; for (int i = 0; i < num; i++) { if (buffer[i] == 10) { string str4 = Encoding.ASCII.GetString(buffer, index, i - index); writer.WriteLine(str4); index = i + 1; } } } else { stream.Write(buffer, 0, num); } goto Label_00E8; } if (flag) { writer.Close(); } else { stream.Close(); } }
public TarEntry GetNextEntry() { if (this.hasHitEOF) { return null; } if (this.currEntry != null) { int numToSkip = this.entrySize - this.entryOffset; if (this.debug) { Console.Error.WriteLine(string.Concat(new object[] { "TarInputStream: SKIP currENTRY '", this.currEntry.Name, "' SZ ", this.entrySize, " OFF ", this.entryOffset, " skipping ", numToSkip, " bytes" })); } if (numToSkip > 0) { this.Skip(numToSkip); } this.readBuf = null; } byte[] record = this.buffer.ReadRecord(); if (record == null) { if (this.debug) { Console.Error.WriteLine("READ NULL RECORD"); } this.hasHitEOF = true; } else if (this.buffer.IsEOFRecord(record)) { if (this.debug) { Console.Error.WriteLine("READ EOF RECORD"); } this.hasHitEOF = true; } if (this.hasHitEOF) { this.currEntry = null; } else { try { if (this.eFactory == null) { this.currEntry = new TarEntry(record); } else { this.currEntry = this.eFactory.CreateEntry(record); } if (((record[0x101] != 0x75) || (record[0x102] != 0x73)) || (((record[0x103] != 0x74) || (record[260] != 0x61)) || (record[0x105] != 0x72))) { throw new InvalidHeaderException(string.Concat(new object[] { "header magic is not 'ustar', but '", record[0x101], record[0x102], record[0x103], record[260], record[0x105], "', or (dec) ", (int) record[0x101], ", ", (int) record[0x102], ", ", (int) record[0x103], ", ", (int) record[260], ", ", (int) record[0x105] })); } if (this.debug) { Console.Error.WriteLine(string.Concat(new object[] { "TarInputStream: SET CURRENTRY '", this.currEntry.Name, "' size = ", this.currEntry.Size })); } this.entryOffset = 0; this.entrySize = (int) this.currEntry.Size; } catch (InvalidHeaderException exception) { this.entrySize = 0; this.entryOffset = 0; this.currEntry = null; throw new InvalidHeaderException(string.Concat(new object[] { "bad header in block ", this.buffer.GetCurrentBlockNum(), " record ", this.buffer.GetCurrentRecordNum(), ", ", exception.Message })); } } return this.currEntry; }
public bool IsDescendent(TarEntry desc) { return desc.header.name.ToString().StartsWith(this.header.name.ToString()); }
public TarEntry[] GetDirectoryEntries() { if ((this.file == null) || !Directory.Exists(this.file)) { return new TarEntry[0]; } string[] fileSystemEntries = Directory.GetFileSystemEntries(this.file); TarEntry[] entryArray = new TarEntry[fileSystemEntries.Length]; string file = this.file; if (!file.EndsWith(Path.DirectorySeparatorChar.ToString())) { file = file + Path.DirectorySeparatorChar; } for (int i = 0; i < fileSystemEntries.Length; i++) { entryArray[i] = CreateEntryFromFile(fileSystemEntries[i]); } return entryArray; }
public static TarEntry CreateTarEntry(string name) { TarEntry entry = new TarEntry(); entry.Initialize(); entry.NameTarHeader(entry.header, name); return entry; }
public static TarEntry CreateEntryFromFile(string fileName) { TarEntry entry = new TarEntry(); entry.Initialize(); entry.GetFileTarHeader(entry.header, fileName); return entry; }