Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

October 16, 2006

Close your Memory Stream before trying to use the data!

I’’m having problems with one customer who repeatedly gets this error when uploading a zip file which is unzipped in memory with ChilKatZip.
OpenFromMemory: Failed to get end-of-directory record.

I also get the same error, but if I extract and then re-zip I get no problems. I’m not sure what their zip program is, but I wondered if you have seen this error before (couldn’t find anything on your site) and if you have any info that might help.

You’re the 3rd customer to recently have this problem. It’s because you wrote the zip using a .NET memory stream and you need to close it first before trying to use the data. The error indicates that the Zip ended prematurely — and it did. That’s because the remainder of the memory stream was not yet flushed. Closing it will flush the stream, and then you can open the zip from memory. This is something to remember in general: whenever using System.IO.MemoryStream, you must close it (or flush it) before using the data written. This is a real pitfall because the bug can escape testing. When forgetting to flush the memory stream, the code may or may not work — it all depends on chance (i.e. whether the buffer contains unflushed data). Thus, you may find it works on one computer but not another, or that sometimes the code works, and sometimes not.

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.