PutNextEntry() public method

Put an entry on the output stream. This writes the entry's header and positions the output stream for writing the contents of the entry. Once this method is called, the stream is ready for calls to write() to write the entry's contents. Once the contents are written, closeEntry() MUST be called to ensure that all buffered data is completely written to the output stream.
public PutNextEntry ( TarEntry entry ) : void
entry TarEntry /// The TarEntry to be written to the archive. ///
return void
示例#1
1
		private void WriteObjectToTar (TarOutputStream  tar_out,
					       FileSystemObject fso,
					       EventTracker     tracker)
		{
			MemoryStream memory = null;

			TarHeader header;
			header = new TarHeader ();

			StringBuilder name_builder;
			name_builder = new StringBuilder (fso.FullName);
			name_builder.Remove (0, this.FullName.Length+1);
			header.Name = name_builder.ToString ();

			header.ModTime = fso.Timestamp;
			if (fso is DirectoryObject) {
				header.Mode = 511; // 0777
				header.TypeFlag = TarHeader.LF_DIR;
				header.Size = 0;
			} else {
				header.Mode = 438; // 0666
				header.TypeFlag = TarHeader.LF_NORMAL;
				memory = new MemoryStream ();
				((FileObject) fso).AddToStream (memory, tracker);
				header.Size = memory.Length;
			}

			TarEntry entry;
			entry = new TarEntry (header);

			tar_out.PutNextEntry (entry);
			if (memory != null) {
				tar_out.Write (memory.ToArray (), 0, (int) memory.Length);
				memory.Close ();
			}
			tar_out.CloseEntry ();

			// If this is a directory, write out the children
			if (fso is DirectoryObject)
				foreach (FileSystemObject child in fso.Children)
					WriteObjectToTar (tar_out, child, tracker);
		}
        public void TestExtractArchiveTarGzCreateContainer()
        {
            CloudFilesProvider provider = (CloudFilesProvider)Bootstrapper.CreateObjectStorageProvider();
            string containerName = TestContainerPrefix + Path.GetRandomFileName();
            string sourceFileName = "DarkKnightRises.jpg";
            byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (GZipOutputStream gzoStream = new GZipOutputStream(outputStream))
                {
                    gzoStream.IsStreamOwner = false;
                    gzoStream.SetLevel(9);
                    using (TarOutputStream tarOutputStream = new TarOutputStream(gzoStream))
                    {
                        tarOutputStream.IsStreamOwner = false;
                        TarEntry entry = TarEntry.CreateTarEntry(containerName + '/' + sourceFileName);
                        entry.Size = content.Length;
                        tarOutputStream.PutNextEntry(entry);
                        tarOutputStream.Write(content, 0, content.Length);
                        tarOutputStream.CloseEntry();
                        tarOutputStream.Close();
                    }
                }

                outputStream.Flush();
                outputStream.Position = 0;
                ExtractArchiveResponse response = provider.ExtractArchive(outputStream, "", ArchiveFormat.TarGz);
                Assert.IsNotNull(response);
                Assert.AreEqual(1, response.CreatedFiles);
                Assert.IsNotNull(response.Errors);
                Assert.AreEqual(0, response.Errors.Count);
            }

            using (MemoryStream downloadStream = new MemoryStream())
            {
                provider.GetObject(containerName, sourceFileName, downloadStream, verifyEtag: true);
                Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));

                downloadStream.Position = 0;
                byte[] actualData = new byte[downloadStream.Length];
                downloadStream.Read(actualData, 0, actualData.Length);
                Assert.AreEqual(content.Length, actualData.Length);
                using (MD5 md5 = MD5.Create())
                {
                    byte[] contentMd5 = md5.ComputeHash(content);
                    byte[] actualMd5 = md5.ComputeHash(actualData);
                    Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
                }
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
示例#3
0
        public void BlockFactorHandling()
		{
			const int MinimumBlockFactor = 1;
			const int MaximumBlockFactor = 64;
			const int FillFactor = 2;

			for ( int factor = MinimumBlockFactor; factor < MaximumBlockFactor; ++factor)
			{
				MemoryStream ms = new MemoryStream();

				using ( TarOutputStream tarOut = new TarOutputStream(ms, factor) )
				{
					TarEntry entry = TarEntry.CreateTarEntry("TestEntry");
					entry.Size = (TarBuffer.BlockSize * factor * FillFactor);
					tarOut.PutNextEntry(entry);

					byte[] buffer = new byte[TarBuffer.BlockSize];

					Random r = new Random();
					r.NextBytes(buffer);

					// Last block is a partial one
					for ( int i = 0; i < factor * FillFactor; ++i)
					{
						tarOut.Write(buffer, 0, buffer.Length);
					}
				}

				byte[] tarData = ms.ToArray();
				Assert.IsNotNull(tarData, "Data written is null");

				// Blocks = Header + Data Blocks + Zero block + Record trailer
				int usedBlocks = 1 + (factor * FillFactor) + 1;
				int totalBlocks = usedBlocks + (factor - 1);
				totalBlocks /= factor;
				totalBlocks *= factor;

				Assert.AreEqual(TarBuffer.BlockSize * totalBlocks, tarData.Length, "Tar file should contain {0} blocks in length",
					totalBlocks);

				if ( usedBlocks < totalBlocks )
				{
					// Start at first byte after header.
					int byteIndex = TarBuffer.BlockSize * ((factor * FillFactor)+ 1);
					while ( byteIndex < tarData.Length )
					{
						int blockNumber = byteIndex / TarBuffer.BlockSize;
						int offset = blockNumber % TarBuffer.BlockSize;
						Assert.AreEqual(0, tarData[byteIndex],
							string.Format("Trailing block data should be null iteration {0} block {1} offset {2}  index {3}",
							factor,
							blockNumber, offset, byteIndex));
						byteIndex += 1;
					}
				}
			}
		}
        public void Checksum()
        {
            MemoryStream ms = new MemoryStream();
            TarOutputStream tarOut = new TarOutputStream(ms);

            DateTime modTime = DateTime.Now;

            TarEntry entry = TarEntry.CreateTarEntry("TestEntry");
            entry.TarHeader.Mode = 12345;

            tarOut.PutNextEntry(entry);
            tarOut.Close();

            MemoryStream ms2 = new MemoryStream();
            ms2.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            ms2.Seek(0, SeekOrigin.Begin);

            TarInputStream tarIn = new TarInputStream(ms2);
            TarEntry nextEntry = tarIn.GetNextEntry();

            Assert.IsTrue(nextEntry.TarHeader.IsChecksumValid, "Checksum should be valid");

            MemoryStream ms3 = new MemoryStream();
            ms3.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            ms3.Seek(0, SeekOrigin.Begin);
            ms3.Write(new byte[1] { 34 }, 0, 1);
            ms3.Seek(0, SeekOrigin.Begin);

            tarIn = new TarInputStream(ms3);
            bool trapped = false;

            try
            {
                nextEntry = tarIn.GetNextEntry();
            }
            catch (TarException)
            {
                trapped = true;
            }

            Assert.IsTrue(trapped, "Checksum should be invalid");
        }
示例#5
0
        /// <summary>
        /// Write an entry to the archive. This method will call the putNextEntry
        /// and then write the contents of the entry, and finally call closeEntry()
        /// for entries that are files. For directories, it will call putNextEntry(),
        /// and then, if the recurse flag is true, process each entry that is a
        /// child of the directory.
        /// </summary>
        /// <param name="sourceEntry">
        /// The TarEntry representing the entry to write to the archive.
        /// </param>
        /// <param name="recurse">
        /// If true, process the children of directory entries.
        /// </param>
        void InternalWriteEntry(TarEntry sourceEntry, bool recurse)
        {
            var asciiTrans = false;

            string tempFileName  = null;
            var    entryFilename = sourceEntry.File;

            var entry = (TarEntry)sourceEntry.Clone();

            if (applyUserInfoOverrides)
            {
                entry.GroupId   = groupId;
                entry.GroupName = groupName;
                entry.UserId    = userId;
                entry.UserName  = userName;
            }

            OnProgressMessageEvent(entry, null);

            if (asciiTranslate && !entry.IsDirectory)
            {
                asciiTrans = !IsBinary(entryFilename);

                if (asciiTrans)
                {
                    tempFileName = Path.GetTempFileName();

                    var    inStream  = File.OpenText(entryFilename);
                    Stream outStream = File.Create(tempFileName);

                    while (true)
                    {
                        var line = inStream.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        var data = Encoding.ASCII.GetBytes(line);
                        outStream.Write(data, 0, data.Length);
                        outStream.WriteByte((byte)'\n');
                    }

                    inStream.Close();

                    outStream.Flush();
                    outStream.Close();

                    entry.Size = new FileInfo(tempFileName).Length;

                    entryFilename = tempFileName;
                }
            }

            string newName = null;

            if (rootPath != null)
            {
                if (entry.Name.StartsWith(rootPath))
                {
                    newName = entry.Name.Substring(rootPath.Length + 1);
                }
            }

            if (pathPrefix != null)
            {
                newName = (newName == null) ? pathPrefix + "/" + entry.Name : pathPrefix + "/" + newName;
            }

            if (newName != null)
            {
                entry.Name = newName;
            }

            tarOut.PutNextEntry(entry);

            if (entry.IsDirectory)
            {
                if (recurse)
                {
                    var list = entry.GetDirectoryEntries();
                    for (var i = 0; i < list.Length; ++i)
                    {
                        InternalWriteEntry(list[i], recurse);
                    }
                }
            }
            else
            {
                Stream inputStream = File.OpenRead(entryFilename);
                var    numWritten  = 0;
                var    eBuf        = new byte[32 * 1024];
                while (true)
                {
                    var numRead = inputStream.Read(eBuf, 0, eBuf.Length);

                    if (numRead <= 0)
                    {
                        break;
                    }

                    tarOut.Write(eBuf, 0, numRead);
                    numWritten += numRead;
                }

                inputStream.Close();

                if (tempFileName != null && tempFileName.Length > 0)
                {
                    File.Delete(tempFileName);
                }

                tarOut.CloseEntry();
            }
        }
示例#6
0
		public void ValuesPreserved()
		{
			MemoryStream ms = new MemoryStream();
			TarEntry entry;
			DateTime modTime = DateTime.Now;

			using (TarOutputStream tarOut = new TarOutputStream(ms))
			{
				entry = TarEntry.CreateTarEntry("TestEntry");
				entry.GroupId = 12;
				entry.UserId = 14;
				entry.ModTime = modTime;
				entry.UserName = "******";
				entry.GroupName = "GroupName";
				entry.TarHeader.Mode = 12345;
			
				tarOut.PutNextEntry(entry);
			}

			MemoryStream ms2 = new MemoryStream();
			ms2.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
			ms2.Seek(0, SeekOrigin.Begin);
			
			using (TarInputStream tarIn = new TarInputStream(ms2))
			{
				TarEntry nextEntry = tarIn.GetNextEntry();
				Assert.AreEqual(entry.TarHeader.Checksum, nextEntry.TarHeader.Checksum, "Checksum");
			
				Assert.IsTrue(nextEntry.Equals(entry), "Entries should be equal");
				Assert.IsTrue(nextEntry.TarHeader.Equals(entry.TarHeader), "Headers should match");

				// Tar only stores seconds 
				DateTime truncatedTime = new DateTime(modTime.Year, modTime.Month, modTime.Day, 
					modTime.Hour, modTime.Minute, modTime.Second);
				Assert.AreEqual(truncatedTime, nextEntry.ModTime, "Modtimes should match");
			
				int entryCount = 0;
				while ( nextEntry != null )
				{
					++entryCount;
					nextEntry = tarIn.GetNextEntry();
				}
			
				Assert.AreEqual(1, entryCount, "Expected 1 entry");
			}
		}
示例#7
0
		void TryLongName(string name)
		{
			MemoryStream ms = new MemoryStream();
			using ( TarOutputStream tarOut = new TarOutputStream(ms) )
			{
				DateTime modTime = DateTime.Now;

				TarEntry entry = TarEntry.CreateTarEntry(name);
				tarOut.PutNextEntry(entry);
			}

			MemoryStream ms2 = new MemoryStream();
			ms2.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
			ms2.Seek(0, SeekOrigin.Begin);

			using (TarInputStream tarIn = new TarInputStream(ms2))
			{
				TarEntry nextEntry = tarIn.GetNextEntry();
			
				Assert.AreEqual(nextEntry.Name, name, "Name match failure");
			}
		}
示例#8
0
        public void TrailerContainsNulls()
		{
			const int TestBlockFactor = 3;

			for ( int iteration = 0; iteration < TestBlockFactor * 2; ++iteration)
			{
				MemoryStream ms = new MemoryStream();

				using ( TarOutputStream tarOut = new TarOutputStream(ms, TestBlockFactor) )
				{
					TarEntry entry = TarEntry.CreateTarEntry("TestEntry");
					if ( iteration > 0 )
					{
						entry.Size = (TarBuffer.BlockSize * (iteration - 1)) + 9;
					}
					tarOut.PutNextEntry(entry);

					byte[] buffer = new byte[TarBuffer.BlockSize];

					Random r = new Random();
					r.NextBytes(buffer);

					if ( iteration > 0 )
					{
						for ( int i = 0; i < iteration - 1; ++i )
						{
							tarOut.Write(buffer, 0, buffer.Length);
						}

						// Last block is a partial one
						for ( int i = 1; i < 10; ++i)
						{
							tarOut.WriteByte((byte)i);
						}
					}
				}

				byte[] tarData = ms.ToArray();
				Assert.IsNotNull(tarData, "Data written is null");

				// Blocks = Header + Data Blocks + Zero block + Record trailer
				int usedBlocks = 1 + iteration + 1;
				int totalBlocks = usedBlocks + (TestBlockFactor - 1);
				totalBlocks /= TestBlockFactor;
				totalBlocks *= TestBlockFactor;

				Assert.AreEqual(TarBuffer.BlockSize * totalBlocks, tarData.Length,
					string.Format("Tar file should be {0} blocks in length", totalBlocks));

				if ( usedBlocks < totalBlocks )
				{
					// Start at first byte after header.
					int byteIndex = TarBuffer.BlockSize * (iteration + 1);
					while ( byteIndex < tarData.Length )
					{
						int blockNumber = byteIndex / TarBuffer.BlockSize;
						int offset = blockNumber % TarBuffer.BlockSize;
						Assert.AreEqual(0, tarData[byteIndex],
							string.Format("Trailing block data should be null iteration {0} block {1} offset {2}  index {3}",
							iteration,
							blockNumber, offset, byteIndex));
						byteIndex += 1;
					}
				}
			}
		}
示例#9
0
        private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
        {
            string   text     = null;
            string   text2    = sourceEntry.File;
            TarEntry tarEntry = (TarEntry)sourceEntry.Clone();

            if (applyUserInfoOverrides)
            {
                tarEntry.GroupId   = groupId;
                tarEntry.GroupName = groupName;
                tarEntry.UserId    = userId;
                tarEntry.UserName  = userName;
            }
            OnProgressMessageEvent(tarEntry, null);
            if (asciiTranslate && !tarEntry.IsDirectory && !IsBinary(text2))
            {
                text = Path.GetTempFileName();
                using (StreamReader streamReader = File.OpenText(text2))
                {
                    using (Stream stream = File.Create(text))
                    {
                        while (true)
                        {
                            string text3 = streamReader.ReadLine();
                            if (text3 == null)
                            {
                                break;
                            }
                            byte[] bytes = Encoding.ASCII.GetBytes(text3);
                            stream.Write(bytes, 0, bytes.Length);
                            stream.WriteByte(10);
                        }
                        stream.Flush();
                    }
                }
                tarEntry.Size = new FileInfo(text).Length;
                text2         = text;
            }
            string text4 = null;

            if (rootPath != null && tarEntry.Name.StartsWith(rootPath))
            {
                text4 = tarEntry.Name.Substring(rootPath.Length + 1);
            }
            if (pathPrefix != null)
            {
                text4 = ((text4 == null) ? (pathPrefix + "/" + tarEntry.Name) : (pathPrefix + "/" + text4));
            }
            if (text4 != null)
            {
                tarEntry.Name = text4;
            }
            tarOut.PutNextEntry(tarEntry);
            if (tarEntry.IsDirectory)
            {
                if (recurse)
                {
                    TarEntry[] directoryEntries = tarEntry.GetDirectoryEntries();
                    for (int i = 0; i < directoryEntries.Length; i++)
                    {
                        WriteEntryCore(directoryEntries[i], recurse);
                    }
                }
            }
            else
            {
                using (Stream stream2 = File.OpenRead(text2))
                {
                    byte[] array = new byte[32768];
                    while (true)
                    {
                        int num = stream2.Read(array, 0, array.Length);
                        if (num <= 0)
                        {
                            break;
                        }
                        tarOut.Write(array, 0, num);
                    }
                }
                if (text != null && text.Length > 0)
                {
                    File.Delete(text);
                }
                tarOut.CloseEntry();
            }
        }
示例#10
0
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            FileInfo fi = null;
            DirectoryInfo din = null;
            DirectoryInfo dout = new DirectoryInfo (dir);

            if (File.Exists (fichero)) {
                fi = new FileInfo (fichero);
            } else if (Directory.Exists (fichero)) {
                din = new DirectoryInfo (fichero);
            } else {
                throw new Exception ("" + fichero + " not found");
            }
            List<FileInfo> files = load (fichero);

            string baseName = "";
            if (fi != null) {
                baseName = fi.Name;
            } else if (din != null) {
                baseName = din.Name;
            }

            if ((sal1 == null) || (sal1 == string.Empty)) {
                //
                if (din != null) {
                    sal1 = din.Name;
                }
                if (fi != null) {
                    sal1 = fi.Name;
                }
            }

            long totalSize = calculateTotalSize (files);
            long fragments = totalSize / (kb * 1024);
            string s = "" + fragments;
            JoinInfo info = new JoinInfo ();
            info.OriginalFile = baseName;
            info.InitialFragment = 0;
            info.Digits = Math.Max (s.Length, 3);
            info.BaseName = sal1 + ".tar.gz.";
            info.Directory = dout;
            info.Length = totalSize;

            Stream stream = new SplitStream (info, kb * 1024, info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + "sha512sum.dalle", "SHA512");
            stream = new GZipStream (stream, CompressionMode.Compress);
            TarOutputStream taros = new TarOutputStream (stream);
            foreach (FileInfo f in files) {

                TarEntry te = TarEntry.CreateEntryFromFile (f.FullName);
                te.UserId = 0;
                te.GroupId = 0;
                te.UserName = String.Empty;
                te.GroupName = String.Empty;
                taros.PutNextEntry (te);
                FileStream fs = f.OpenRead ();
                long leidosTotales = 0;
                byte[] buffer = new byte[Consts.BUFFER_LENGTH];
                int leidos = 0;
                while ((leidos = fs.Read (buffer, 0, buffer.Length)) > 0) {
                    taros.Write (buffer, 0, leidos);
                    leidosTotales += leidos;
                    OnProgress (leidosTotales, totalSize);
                }
                taros.CloseEntry ();
                fs.Close ();
            }
            taros.Close ();
            OnProgress (totalSize, totalSize);
        }
示例#11
0
        /// <summary>
        /// Write an entry to the archive. This method will call the putNextEntry
        /// and then write the contents of the entry, and finally call closeEntry()
        /// for entries that are files. For directories, it will call putNextEntry(),
        /// and then, if the recurse flag is true, process each entry that is a
        /// child of the directory.
        /// </summary>
        /// <param name="sourceEntry">
        /// The TarEntry representing the entry to write to the archive.
        /// </param>
        /// <param name="recurse">
        /// If true, process the children of directory entries.
        /// </param>
        void WriteEntryCore(TarEntry sourceEntry, bool recurse)
        {
            string tempFileName  = null;
            string entryFilename = sourceEntry.File;

            TarEntry entry = (TarEntry)sourceEntry.Clone();

            if (applyUserInfoOverrides)
            {
                entry.GroupId   = groupId;
                entry.GroupName = groupName;
                entry.UserId    = userId;
                entry.UserName  = userName;
            }

            OnProgressMessageEvent(entry, null);

            if (asciiTranslate && !entry.IsDirectory)
            {
                if (!IsBinary(entryFilename))
                {
                    tempFileName = Path.GetTempFileName();

                    using (StreamReader inStream = File.OpenText(entryFilename)) {
                        using (Stream outStream = File.Create(tempFileName)) {
                            while (true)
                            {
                                string line = inStream.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }
                                byte[] data = Encoding.UTF8.GetBytes(line);
                                outStream.Write(data, 0, data.Length);
                                outStream.WriteByte((byte)'\n');
                            }

                            outStream.Flush();
                        }
                    }

                    entry.Size    = new FileInfo(tempFileName).Length;
                    entryFilename = tempFileName;
                }
            }

            string newName = null;

            if (rootPath != null)
            {
                if (entry.Name.StartsWith(rootPath))
                {
                    newName = entry.Name.Substring(rootPath.Length + 1);
                }
            }

            if (pathPrefix != null)
            {
                newName = (newName == null) ? pathPrefix + "/" + entry.Name : pathPrefix + "/" + newName;
            }

            if (newName != null)
            {
                entry.Name = newName;
            }

            tarOut.PutNextEntry(entry);

            if (entry.IsDirectory)
            {
                if (recurse)
                {
                    TarEntry[] list = entry.GetDirectoryEntries();
                    for (int i = 0; i < list.Length; ++i)
                    {
                        WriteEntryCore(list[i], recurse);
                    }
                }
            }
            else
            {
                using (Stream inputStream = File.OpenRead(entryFilename)) {
                    byte[] localBuffer = new byte[32 * 1024];
                    while (true)
                    {
                        int numRead = inputStream.Read(localBuffer, 0, localBuffer.Length);

                        if (numRead <= 0)
                        {
                            break;
                        }

                        tarOut.Write(localBuffer, 0, numRead);
                    }
                }

                if ((tempFileName != null) && (tempFileName.Length > 0))
                {
                    File.Delete(tempFileName);
                }

                tarOut.CloseEntry();
            }
        }
示例#12
0
 private void TarFile(TarOutputStream stream, IPurePath baseDir, IPurePath sourcePath)
 {
     var tarName = baseDir.WithFilename(sourcePath.Filename);
     var entry = TarEntry.CreateTarEntry(tarName.ToString());
     using (var file = File.OpenRead(sourcePath.ToString()))
     {
         entry.Size = file.Length;
         stream.PutNextEntry(entry);
         file.CopyTo(stream);
     }
     stream.CloseEntry();
 }
示例#13
0
        private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
        {
            //IL_00de: Unknown result type (might be due to invalid IL or missing references)
            string   text     = null;
            string   text2    = sourceEntry.File;
            TarEntry tarEntry = (TarEntry)sourceEntry.Clone();

            if (applyUserInfoOverrides)
            {
                tarEntry.GroupId   = groupId;
                tarEntry.GroupName = groupName;
                tarEntry.UserId    = userId;
                tarEntry.UserName  = userName;
            }
            OnProgressMessageEvent(tarEntry, null);
            if (asciiTranslate && !tarEntry.IsDirectory && !IsBinary(text2))
            {
                text = Path.GetTempFileName();
                StreamReader val = File.OpenText(text2);
                try
                {
                    Stream val2 = (Stream)(object)File.Create(text);
                    try
                    {
                        while (true)
                        {
                            string text3 = ((TextReader)val).ReadLine();
                            if (text3 == null)
                            {
                                break;
                            }
                            byte[] bytes = Encoding.get_ASCII().GetBytes(text3);
                            val2.Write(bytes, 0, bytes.Length);
                            val2.WriteByte((byte)10);
                        }
                        val2.Flush();
                    }
                    finally
                    {
                        ((global::System.IDisposable)val2)?.Dispose();
                    }
                }
                finally
                {
                    ((global::System.IDisposable)val)?.Dispose();
                }
                tarEntry.Size = new FileInfo(text).get_Length();
                text2         = text;
            }
            string text4 = null;

            if (rootPath != null && tarEntry.Name.StartsWith(rootPath))
            {
                text4 = tarEntry.Name.Substring(rootPath.get_Length() + 1);
            }
            if (pathPrefix != null)
            {
                text4 = ((text4 == null) ? (pathPrefix + "/" + tarEntry.Name) : (pathPrefix + "/" + text4));
            }
            if (text4 != null)
            {
                tarEntry.Name = text4;
            }
            tarOut.PutNextEntry(tarEntry);
            if (tarEntry.IsDirectory)
            {
                if (recurse)
                {
                    TarEntry[] directoryEntries = tarEntry.GetDirectoryEntries();
                    for (int i = 0; i < directoryEntries.Length; i++)
                    {
                        WriteEntryCore(directoryEntries[i], recurse);
                    }
                }
                return;
            }
            Stream val3 = (Stream)(object)File.OpenRead(text2);

            try
            {
                byte[] array = new byte[32768];
                while (true)
                {
                    int num = val3.Read(array, 0, array.Length);
                    if (num > 0)
                    {
                        ((Stream)tarOut).Write(array, 0, num);
                        continue;
                    }
                    break;
                }
            }
            finally
            {
                ((global::System.IDisposable)val3)?.Dispose();
            }
            if (text != null && text.get_Length() > 0)
            {
                File.Delete(text);
            }
            tarOut.CloseEntry();
        }