0

This question is a follow up question of

Read binary file from a zip file from C# without unzipping it

After read the bin file from the zip file, I read it and make some changes to the data (id1, id2, value1) and then write to a new memorystream.

Then, in C#, I remove the zipentry from the zip file and add the new memorystream as a zip entry with the same name.

 // read data and made changes, then write to a MemoryStream called myms 
 MemoryStream myms = new MemoryStream();
 // then 
 ZipFile.RemoveEntry(binFileName); // remove the file with non-normalized rm factors
 ZipFile.AddEntry("subFolder/" + binFileName, myms.ToArray());

After all is done, I manually unzipped the zip file and found that the date and time of the binFile is still the time when it was created one week ago not the new time where it was replaced.

How to make sure that the new data has been written to the binFile ?

Community
  • 1
  • 1
user3448011
  • 1,469
  • 1
  • 17
  • 39
  • Perhaps you should also mention from which library this ZipFile class is that you use (or set the library's tag in the question) –  May 09 '17 at 18:52
  • Another question: Was the old file actually deleted and the new file actually written to the ZIP archive? I.e., if you extract the file from the ZIP archive again (after running your code, of course), do you get the file with the old data, or do you get the file with the new data? –  May 09 '17 at 18:56
  • In debug mode, I can see the old data and the old one is removed from zipentries. Also, the new zip entry is also added to the zip file by monitoring the total count of zip entries in the zip file. – user3448011 May 09 '17 at 19:05
  • The ZipFile is from Ionic.Zip.dll. – user3448011 May 09 '17 at 19:06
  • 1
    FYI: The library you are using is called "dotnetzip". When you have further questions in the future about working with ZipFile, you might add the "dotnetzip" tag to your question ;) –  May 09 '17 at 19:09
  • What about the actual ZIP archive? You haven't understood my question, i fear. Have you tried to **extract the file from the archive again**? (for example with 7-zip, WinRar, or the ZIP functionality of the Windows Explorer). Has the **extracted** file in the ZIP archive the expected new data you wrote with your program, or is it still the old data? –  May 09 '17 at 19:12
  • I have unzipped it with winZip. I can see the binFile that should be replaced. But, the binFile date/time is old rather than the time that I replaced it from C#. – user3448011 May 09 '17 at 19:30
  • How to verify the new data has been written into the file ? Read it from C# again to check it ? – user3448011 May 09 '17 at 19:31
  • I don't know. How you most easily/conveniently check the file depends on the type of the file, no? If it is just binary data, use a Hex editor/viewer. If it is some document format, use an appropriate viewer for it. If it is merely a text file of some kind, use a text editor. Do not program something in C# to check the file content. Chances are you do a mistake in your programming which would make such a self-programmed check potentially produce false results... –  May 09 '17 at 19:33
  • I can open it with hexedit in cygwin, but, it is still not human readable. – user3448011 May 09 '17 at 20:31
  • So what. You know what should be in the file. So you should be able to tell whether what you see is the expected file content, right? Or did i misunderstand you? –  May 09 '17 at 21:16

0 Answers0