1

I have a tar.bz2 file and I want to extract it to a directory. In the examples I only see option of compress or decompress however I want actually to extract or unpack.

Also tried ICSharpCode.SharpZipLib.BZip2 but I didn't find an option to unpack.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Barak Rosenfeld
  • 394
  • 5
  • 18

2 Answers2

0

While you use a ZipInputStream for .zip files, you should use a BZip2InputStream for .bz2 files (and GZipInputStream for .gz files etc.).

Taken from:

How to decompress .bz2 file in C#?

Community
  • 1
  • 1
Ariel D.
  • 16
  • 1
  • Just unzipping a file won't unpack it. The content of a tar.bz2 file is just a single tar file, which has to be unpacked to get the single files. – derpirscher Mar 15 '16 at 16:14
0

Decompressing and unpacking are two different operations. A foo.tar.bz2 file is actually a foo.tar file which was then compressed using bz2.

So to get single files you have to do this in the opposite direction. I.e. first decompress it (which you managed to do with sharpziplib). The result of this decompression has then to be untared (which can also be done with sharpziplib) see the docs for details.

derpirscher
  • 14,418
  • 3
  • 18
  • 35