Question

I hava an application that reads a file from a ZIP archive and saves it to file on file system. After writing it to file system I start start immediately to read this file with a SAX2 reader. On bigger files (300+ MB) it sometimes occures, that SAX2 stops parsing because of an unclosed tag. But when I check the file (or even try to read it again later) it works, so the file it self it OK.

FZipKit.ExtractToStream(LFileName, LStream);
LStream.SaveToFile(OutputFilename);
SAX2.processUrl(OutputFilename);

My assumption is, that the file was not yet fully written to file system when I started the parsing process.

Is there a way to ensure, that the file was written or the steam has been flushed to file system?

thx

Was it helpful?

Solution

I'm going to first of all assume that the XML parser operates correctly. If it is incapable of reading files, well the solution is obvious.

Which leads us to look at how the file is created. When you call SaveToFile, the file is opened, written, closed and buffers are flushed. In a plain vanilla system, your XML parser will see the entire content of the file. The only conclusion is that something is interfering. The most like suspect is your virus scanner. Many scanners, even the most respected ones, cannot properly handle a file being closed and then immediately re-opened.

The bottom line is that your code is fine and the problem almost certainly lies with your local environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top