1

I have an application which extracts targz files, I would like a ProgressBar to view the progress of extracting.

But I just have this:

public void ExtractTGZ(String gzArchiveName, String destFolder) 
{
    Stream inStream = File.OpenRead(gzArchiveName);
    Stream gzipStream = new GZipInputStream(inStream);

    TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
    tarArchive.ExtractContents(destFolder);
    tarArchive.Close();

    gzipStream.Close();
    inStream.Close();
}  

Have you got any ideas? I actually searched how to know the bytes transfered and the total bytes. I didn't find information about this and for targz file specifically.

codeaviator
  • 2,545
  • 17
  • 42
Neyoh
  • 623
  • 1
  • 11
  • 33

1 Answers1

1

You will not be able to do it using ExtractContents. It is a synchronous function meaning it will run till the end before returning and you have no way of getting its progress before it returns.

The usual way of getting feedback would be to add an asynchronous callback function to the extraction method and then have the extraction method asynchronously report progress through this callback. However the SharpZipLib API does not support this directly, as far as I can tell from a quick breeze through the docs. You will have to create this functionality yourself.

You can take a look at This example on how to control the extraction from the tar or Find inspiration in the implementation of ExtractContents

You could then either report progress in terms of total_entries / processed_entries or total_bytes / processed_bytes.

As for making the async callback Take a look here. It is not exactly what you are doing but the accepted answer illustrates how to use asynchronous calls.

Community
  • 1
  • 1
Jonas
  • 491
  • 6
  • 22
  • Thank you for details. i'll look the documentation of full control extraction and i hope that i will succeed in doing something. – Neyoh May 06 '15 at 07:17