0

I have a .tar file containing multiple compressed .gz files. I have no issue itterating through the .tar file creating each .gz file in a destination directory. I'd like to skip writting the .gz all together and just decompress it from the TarEntry/TarArchive? and write its contents on the fly via the .Net native GZipStream. Not even sure this is possible.

Here is my current code that writes each g'zipped file out. Not sure what to modify to get where I need to be.

        using (FileStream _fsIn = new FileStream(@"F:\data\abc.tar", FileMode.Open, FileAccess.Read))
        {
            using (TarInputStream _tarIn = new TarInputStream(_fsIn))
            {
                TarEntry _tarEntry;

                while ((_tarEntry = _tarIn.GetNextEntry()) != null)
                {
                    string _archiveName = _tarEntry.Name;

                    using (FileStream _outStr = new FileStream(@"F:\data\" + _archiveName, FileMode.Create))
                    {
                        _tarIn.CopyEntryContents(_outStr);
                    }
                }
            }
        }
BeerGuy
  • 205
  • 1
  • 6

1 Answers1

0

I'am not sure what you want to do. Maybe you can clarify your aim. The sharpzlib is not that good documented as I Expected to be.

I've iterated through a tar archive and pushed the content of a file into a new Stream, maybe you can use this as a starting point. Have a look at this StackOverflow Article

Community
  • 1
  • 1
graugans
  • 240
  • 3
  • 14
  • Let me try to re-explain the scenario. I have a tar file: abc.tar. It contains multiple gzipped files: 1.gz, 2.gz, 3.gz, etc. I have no problem interating through abc.tar and writing out all the gz files contained within. I would like to forgo writing the gz file and just decompress it while looping through abc.tar. – BeerGuy Apr 21 '11 at 17:17
  • I'll give the following code a try from the article you provided. Due to the obscene gz file size, this probably isn't a good fit. MemoryStream out_stream = new MemoryStream(); tar.CopyEntryContents(out_stream); – BeerGuy Apr 21 '11 at 17:24