How to output zip file in Text vs Binary format

Sep 30, 2009 at 9:51 PM

Hi,

I have Ionic.Zip 1.8.4.24 and using it to create password protected zip file from text file,  that are used as an input to IBM Mainframe.

I run into problem that the file I produce diagrammatically is in the binary format.

Even though PKZIP on Mainframe seems to be able to extract the file,

the system into which the file is supposed to be inputed complains that the file is in Binary format.

If I manually create a zip file  from the same text file using WinZip, then MF system accepts it, specifying that it's format is text.

Can you help?

snippets of code to do actual ziping:

using Ionic.Zip;

...

 

   try
   {
using (ZipFile zip = new ZipFile())
{
zip.Password = "!P@WD#";
zip.AddFile(FileName, "");
zip.Save(ZipFileName);
}
}
   catch (System.Exception ex1)
   {
     System.Console.Error.WriteLine("exception: " + ex1);
   }

   try

   {

using (ZipFile zip = new ZipFile())

{

zip.Password = "somepassword";

zip.AddFile(FileName, "");

zip.Save(ZipFileName);

}

}

   catch (System.Exception ex1)

   {

     System.Console.Error.WriteLine("exception: " + ex1);

   }

 

Coordinator
Sep 30, 2009 at 9:57 PM

Yes, try setting the IsText property on the ZipEntry:

  try
  {
    using (ZipFile zip = new ZipFile())
    {
      zip.Password = "somepassword";
      var e= zip.AddFile(FileName, "");
      e.IsText = true;
      zip.Save(ZipFileName);
    }
  }
  catch (System.Exception ex1)
  {
    System.Console.Error.WriteLine("exception: " + ex1);
  }

Coordinator
Sep 30, 2009 at 11:03 PM
Edited Oct 2, 2009 at 9:10 PM

ps: I considered making this setting automatic - in other words it would get set with the content of the file.  But with Unicode and other text encodings, it's not trivial to say whether a file is "a text file" or "a binary file".  It sort of loses its meaning.  Because of that, the property of entries within a zip file has fallen into disuse now.  But I guess older mainframe apps still use it.  The IsText property was added a while back to DotNetZip to satisfy a person who was sending zips to a mainframe.

I could go part-way, and mark an entry as text if all of the bytes are in the ASCII range, I guess.  But I didn't want to do a half-job, and examining each byte would be a huge performance hit.  I could also mark an entry as text based on the extension of the entry (like *.txt gets marked as text), but that would also not be very complete.  So in the end I made it a manual property that the application must set.   

Oct 1, 2009 at 4:00 PM

Great!

I've added the suggested change and now is awaiting the results from Mainframe guys, hopefully it will do the trick!

Thanks for your help,

miketro