[
  {
    "Id": "272878",
    "ThreadId": "79684",
    "Html": "<p>Hello and happy new year =3</p>\r\n<p>&nbsp;</p>\r\n<p>I tried to convert compressed ZIP files into uncompressed ones, using a memory stream to reduce HDD usage, but I got this error:</p>\r\n<p><span style=\"color:#800000\">ZipEntry::ReadHeader(): Bad signature (0xE0FFD8FF) at position  0x00000000</span></p>\r\n<p>Here is some code:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\"><br>using</span>( MemoryStream stream = <span style=\"color:Blue\">new</span> MemoryStream() )\r\n{\r\n\t<span style=\"color:Blue\">using</span>( ZipFile zipOrg = ZipFile.Read( filepath ) )\r\n\t{\r\n\t\t<span style=\"color:Blue\">foreach</span>( ZipEntry entry <span style=\"color:Blue\">in</span> zipOrg )\r\n\t\t\tentry.Extract( stream );\r\n\t\t<span style=\"color:Green\">//\tusing( Stream s = entry.OpenReader() ) s.CopyTo( stream );</span>\r\n\t}\r\n\r\n<span style=\"color:Green\">//\tFile.Delete( filepath );</span>\r\n\tstream.Seek( 0, SeekOrigin.Begin );\r\n\r\n\t<span style=\"color:Blue\">using</span>( ZipFile zipNew = <span style=\"color:#800000\">ZipFile.Read( stream )</span> )\r\n\t{\r\n\t\tzipNew.CompressionLevel = Ionic.Zlib.CompressionLevel.None;\r\n\t\tzipNew.Save( filepathDebug ); <span style=\"color:Green\">// filepath</span>\r\n\t}\r\n}\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p><span style=\"color:#000000\">0xE0FFD8FF is the proper signature for a JPEG file, so what could be wrong ?</span></p>\r\n<p>&nbsp;</p>\r\n<p>Using &quot;Ionic.Zip.Reduced.dll&quot; v1.8.4.28.</p>",
    "PostedDate": "2010-01-04T06:20:50.32-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "273027",
    "ThreadId": "79684",
    "Html": "<p>I think what you've done is extract the first entry of a zip file, into memory (a MemoryStream).&nbsp;</p>\r\n<p>At that point you've tried to READ that MemoryStream as if it is a zip file.&nbsp; This error that you receive is telling you that no, the data contained in the MemoryStream is a JPG file.&nbsp;</p>\r\n<p>Does that sound possible?&nbsp;</p>\r\n<p>This would work, if the first entry in the zip file, were another zip file. But in your case, it is a JPG file.</p>\r\n<p>I'm not sure what you're trying to do, by extracting a zipfile into a stream.&nbsp; Maybe you could explain the goal and I'll be able to make better suggestions.&nbsp; What are you planning to do with the MemoryStream, once you've got a zip entry extracted into it?</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-04T12:00:25.633-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "273467",
    "ThreadId": "79684",
    "Html": "<p>My goal in 3 steps :p<br><br>1. &quot;c:\\blah.zip&quot; --&gt; compression ratio: 0.97<br>2. Calling a magic function that only uses one memory stream.<br>3. &quot;c:\\blah.zip&quot; --&gt; compression ratio: 1<br><br>But it seems I was wrong in both form and content.<br><br>Form because obviously I should use &quot;new ZipFile()&quot; + &quot;ZipFile::AddEntry( name, stream )&quot; instead of &quot;ZipFile.Read( stream )&quot; which is more for http/ftp use (sorry for your lost time on that first post).<br><br>Content because it doesnt seem possible to do it with only one stream. There's no way to tell the size of the entry being added, so DotNetZip read from the given position to the very end. So if the original ZIP contains 3 files of respectivly 40, 50 and 60 KB once uncompressed, the files size in the new ZIP would be either 150, 110, 60 or 150, 0, 0 (depending of the way to do it).<br><br>I suppose I will have to open 1 stream per file in the given ZIP ? It would give this kind of (not particularly elegant ._.) code :</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>List&lt;Stream&gt; streams = <span style=\"color:Blue\">new</span> List&lt;Stream&gt;();\r\n\r\n<span style=\"color:Blue\">using</span>( ZipFile zipNew = <span style=\"color:Blue\">new</span> ZipFile() )\r\n{\r\n\tzipNew.CompressionLevel = Ionic.Zlib.CompressionLevel.None;\r\n\t<span style=\"color:Blue\">using</span>( ZipFile zipOrg = ZipFile.Read( fileName ) )\r\n\t{\r\n\t\t<span style=\"color:Blue\">foreach</span>( ZipEntry entry <span style=\"color:Blue\">in</span> zipOrg )\r\n\t\t{\r\n\t\t\tMemoryStream stream = <span style=\"color:Blue\">new</span> MemoryStream( (<span style=\"color:Blue\">int</span>) entry.UncompressedSize );\r\n\t\t<span style=\"color:Green\">//\tStream stream = entry.OpenReader();</span>\r\n\t\t\tentry.Extract( stream );\r\n\t\t\tstream.Position = 0;\r\n\t\t\tzipNew.AddEntry( entry.FileName, stream );\r\n\t\t\tstreams.Add( stream );\r\n\t\t}\r\n\t}\r\n\tzipNew.Save( fileName );\r\n}\r\n\r\n<span style=\"color:Blue\">foreach</span>( Stream stream <span style=\"color:Blue\">in</span> streams )\r\n\tstream.Close();\r\n\r\n</pre>\r\n</div>",
    "PostedDate": "2010-01-05T12:51:04.227-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "273546",
    "ThreadId": "79684",
    "Html": "<p>You want to convert a&nbsp;zipfile so that compression is used on none of the entries?&nbsp;</p>\r\n<p>Ideally you could just read in the file, set the CompressionMethod on each entry, then re-save:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span>( ZipFile zipNew = ZipFile.Read( file ) )\r\n{\r\n    <span style=\"color:Blue\">foreach</span> (ZipEntry e <span style=\"color:Blue\">in</span>  zipNew) \r\n    {\r\n        e.CompressionMethod = Ionic.Zip.CompressionMethod.None;\r\n    }\r\n    zipNew.Save( filePath ); \r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>It should be equivalent to read in the file, then set the CompressionLevel on each entry, then re-save.</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span>( ZipFile zipNew = ZipFile.Read( file ) )\r\n{\r\n    <span style=\"color:Blue\">foreach</span> (ZipEntry e <span style=\"color:Blue\">in</span>  zipNew) \r\n    {\r\n        e.CompressionLevel = Ionic.Zlib.CompressionLevel.None;\r\n    }\r\n    zipNew.Save( filePath ); \r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>I always intended for this to work, but when I looked today, I hadn't implemented it.&nbsp; ???&nbsp;I've just implemented it now.&nbsp; You will need v1.9.0.37&nbsp; to get this.&nbsp; I will post it after running a few tests.</p>\r\n<p>If you are using v1.8, then you can do something like this:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = ZipFile.Read(zipFile))\r\n{\r\n    ZipEntry[] list = <span style=\"color:Blue\">new</span> ZipEntry[zip.Entries.Count];\r\n    zip.Entries.CopyTo(list, 0);\r\n    <span style=\"color:Blue\">foreach</span> (ZipEntry e <span style=\"color:Blue\">in</span> list)\r\n    {\r\n        <span style=\"color:Blue\">var</span> e2 = zip.UpdateEntry(e.FileName, <span style=\"color:#A31515\">&quot;&quot;</span>, e.OpenReader());\r\n        e2.CompressionMethod = 0;\r\n    }\r\n    zip.Save();\r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>What any of these options do, is this:&nbsp; as the updated zip is written, it reads the old entry from a stream connected to the old zip file, and writes that content into the updated zip, where it uses the updated CompressionMethod/Level.&nbsp; In the v1.9 versions, it happens automatically and implicitly, inside the library.&nbsp; In the v1.8 code, you have to explicitly open the stream and hand it back to DotNetZip.&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-05T16:05:48.1-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "273567",
    "ThreadId": "79684",
    "Html": "I will look into v1.9, looks good, also I wanted to try the promising multi-thread/core addition =3~~\r\n\r\nThank you for your detailed answers and dedicated support =^.^=\r\n",
    "PostedDate": "2010-01-05T17:33:26.853-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "274154",
    "ThreadId": "79684",
    "Html": "<p>ok Ara,</p>\r\n<p>v1.9.0.37 is up and available.&nbsp; With this release of DotNetZip, you can now do this:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span>( ZipFile zipNew = ZipFile.Read( file ) )\r\n{\r\n    <span style=\"color:Blue\">foreach</span> (ZipEntry e <span style=\"color:Blue\">in</span>  zipNew) \r\n    {\r\n        e.CompressionLevel = Ionic.Zlib.CompressionLevel.None;\r\n    }\r\n    zipNew.Save( filePath ); \r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-06T23:03:33.763-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "274227",
    "ThreadId": "79684",
    "Html": "<p>Neat and working like a charm, thank you&nbsp;=3</p>",
    "PostedDate": "2010-01-07T02:23:39.763-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]