CopyEntryContents() public method

Copies the contents of the current tar archive entry directly into an output stream.
public CopyEntryContents ( Stream outputStream ) : void
outputStream Stream /// The OutputStream into which to write the entry's data. ///
return void
Beispiel #1
0
        private void ExtractEntry(string destDir, TarEntry entry, ICSharpCode.SharpZipLib.Tar.TarInputStream stream)
        {
            string name = entry.Name;

            if (Path.IsPathRooted(name))
            {
                name = name.Substring(Path.GetPathRoot(name).Length);
            }
            name = name.Replace('/', Path.DirectorySeparatorChar);
            name = name.Substring(name.IndexOf(Path.DirectorySeparatorChar) + 1);

            string dest = Path.Combine(destDir, name);

            if (entry.IsDirectory)
            {
                Directory.CreateDirectory(dest);
            }
            else
            {
                Directory.CreateDirectory(Path.GetDirectoryName(dest));
                using (Stream outputStream = File.Create(dest)) {
                    stream.CopyEntryContents(outputStream);
                }
            }
        }
        void UnpackTar(Stream strm)
        {
            TarInputStream tar = new TarInputStream(strm);

            byte[] tempBuf = new byte[65536];
            progressBar2.Style = ProgressBarStyle.Marquee;
            int done = 0;
            for (; ; )
            {
                TarEntry entry = tar.GetNextEntry();
                if (entry == null)
                    break;

                string strName = entry.Name;
                string firstComponent = strName.Substring(0, strName.IndexOf('/'));
                if (firstComponent.ToUpper() == m_NamePrefixToDrop.ToUpper())
                    strName = strName.Substring(m_NamePrefixToDrop.Length + 1);

                if (strName == "")
                    continue;

                string fn = m_Dir + "\\" + strName;

                if ((_Filter == null) || (_Filter(strName)))
                    if (entry.IsDirectory)
                    {
                        if (!Directory.Exists(fn))
                            Directory.CreateDirectory(fn);
                    }
                    else
                        using (FileStream ostrm = new FileStream(fn, FileMode.Create))
                            tar.CopyEntryContents(ostrm);
                if ((done += (int)entry.Size) > progressBar2.Maximum)
                    done = progressBar2.Maximum;
                progressBar2.Value = done;
                Application.DoEvents();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Enumerate through the files of a TAR and get a list of KVP names-byte arrays
        /// </summary>
        /// <param name="stream">The input tar stream</param>
        /// <param name="isTarGz">True if the input stream is a .tar.gz or .tgz</param>
        /// <returns>An enumerable containing each tar entry and it's contents</returns>
        public static IEnumerable<KeyValuePair<string, byte[]>> UnTar(Stream stream, bool isTarGz)
        {
            using (var tar = new TarInputStream(isTarGz ? (Stream)new GZipInputStream(stream) : stream))
            {
                TarEntry entry;
                while ((entry = tar.GetNextEntry()) != null)
                {
                    if (entry.IsDirectory) continue;

                    using (var output = new MemoryStream())
                    {
                        tar.CopyEntryContents(output);
                        yield return new KeyValuePair<string, byte[]>(entry.Name, output.ToArray());
                    }
                }
            }
        }
Beispiel #4
0
 private void processTask(RestoreTask task)
 {
     Logger.Debug("StorageThread:processTask:RestoreTask");
     Stream inStream = File.OpenRead(task.ArchivePath);
     Stream gzipStream = new GZipInputStream(inStream);
     TarInputStream tarStream = new TarInputStream(gzipStream);
     TarEntry entry;
     List<string> list = task.RelativeFilenames();
     RecoverResult recover = new RecoverResult(task.OutputDir, true);
     while ((entry = tarStream.GetNextEntry()) != null)
     {
         if (entry.IsDirectory) continue;
         if (list.IndexOf(entry.Name) != -1)
         {
             string name = entry.Name.Replace('/', Path.DirectorySeparatorChar);
             name = Path.Combine(task.OutputDir, name);
             Directory.CreateDirectory(Path.GetDirectoryName(name));
             FileStream outStream = new FileStream(name, FileMode.CreateNew);
             tarStream.CopyEntryContents(outStream);
             outStream.Close();
             DateTime myDt = DateTime.SpecifyKind(entry.ModTime, DateTimeKind.Utc);
             File.SetLastWriteTime(name, myDt);
         }
     }
     tarStream.Close();
     lock (_lock)
     {
         recoverResults.Enqueue(recover);
     }
 }