0

I have the following code which decompress the bz2 file given to variable zipFileName ,I want to change the code to decompress in the same folder/file structure as present in .bz2 file?please suggest how to do that.

using System;
using System.IO;
using ICSharpCode.SharpZipLib.BZip2;
class Program
    {

    static void Main(string[] args)
        {

        var zipFileName = @"C:\Temp\bins-hw.2.tar.bz2";
        using (FileStream fileToDecompressAsStream = System.IO.File.OpenRead(zipFileName))
        {
            string decompressedFileName = @"C:\Temp\ichsarp\decompressed.txt";
            using (FileStream decompressedStream = File.Create(decompressedFileName))
            {
                try
                {
                    BZip2.Decompress(fileToDecompressAsStream, decompressedStream, true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }

    }
    }
Sparrow
  • 2,548
  • 1
  • 24
  • 28
Ritz
  • 1,193
  • 6
  • 15
  • 26
  • Very important to understand: the structure is the `tar` file, `bz2` just compresses the thing. So, you are right in decompressing the file first, but that will just give you a tar file from which you need to retrieve the files. There are [c# libraries to manipulate tar files](http://stackoverflow.com/questions/8863875/decompress-tar-files-using-c-sharp) – fvu Sep 14 '16 at 20:35
  • fvu - I dont see any tar file under `C:\Temp\ichsarp` ,it just has the file `decompressed.txt`,am I missing something? – Ritz Sep 14 '16 at 20:40
  • The point is, there's no folder/file structure in a .bz2 file. It compresses a single file and that's it. compressing multiple files/folders is usually accomplished by using `tar` to smoosh them all into one file and then compress that smooshed file. You're just compressing a single file (decompressed.txt) so `tar` isn't involved. However, that doesn't change the fact that there's no folder/file structure in a .bz2 file. – itsme86 Sep 14 '16 at 21:11

0 Answers0