0

SharpZipLib is a .Net implementation for Java library for working with archives. It provides ZipOutputStream class, which derives from DeflaterOutputStream and has Finish() method. In the docs here it is stated that the Finish() method "will write the central directory at the end of the zip file and flush the stream" and that it "is automatically called when the stream is closed". So I wonder if I should call Finish() method at all if I call Close() anyway.

UPDATE: the question should have been stated another way: why should I use Finish() method if I can call Dispose() or Close() that will do the job (including calling Finish() method)?

Eleonora
  • 3
  • 2

1 Answers1

0

From the documentation of ZipOutputStream - Finish():

This is automatically called when the stream is closed.

As for the closing, the ZipOutputStream needs to be properly disposed. There is no need to call for Close method.

using (var zip = new ZipOutputStream(new FileStream("some path", FileMode.OpenOrCreate)))
{
    // add some files.
   
}
EylM
  • 5,967
  • 2
  • 16
  • 28
  • 1
    Thak you for the answer! As I see, ZipOutputStream does not override Dispose method, and uses the one defined in Stream - and it in turn just calls the Close method, so It seems that these two options are equivalent – Eleonora Jun 24 '21 at 14:27