{
  "WorkItem": {
    "AffectedComponent": {
      "Name": "",
      "DisplayName": ""
    },
    "ClosedComment": "",
    "ClosedDate": null,
    "CommentCount": 0,
    "Custom": null,
    "Description": "Hello there,\n \nI have a Zip file with the following structure:\n \nf01.jpg\nf02.jpg\nf03.txt\n \nI want to separate the files by extension, each one in your right Zip file. I tried to do this with the code below\n \n            using (ZipFile zipFileSource = ZipFile.Read(@\"D:\\Zips\\ZipSource.zip\"),\n                zipFileJPGs = new ZipFile(),\n                zipFileTXTs = new ZipFile())\n            {\n                foreach (ZipEntry zipEntrySource in zipFileSource)\n                {\n                    if (zipEntrySource.FileName.EndsWith(\"jpg\"))\n                    {\n                        zipFileJPGs.AddEntry(zipEntrySource.FileName, zipEntrySource.OpenReader());\n                    }\n                    else if (zipEntrySource.FileName.EndsWith(\"txt\"))\n                    {\n                        zipFileTXTs.AddEntry(zipEntrySource.FileName, zipEntrySource.OpenReader());\n                    }\n                }\n \n                zipFileJPGs.Save(@\"D:\\Zips\\ZipJPGs.zip\");\n                zipFileTXTs.Save(@\"D:\\Zips\\ZipTXTs.zip\");\n            }\n \nbut I didn't have sucess. Any sugestions?\n \n \nThankfully,\n \nRosberg Linhares",
    "LastUpdatedDate": "2013-02-21T18:43:04.363-08:00",
    "PlannedForRelease": "",
    "ReleaseVisibleToPublic": false,
    "Priority": {
      "Name": "Low",
      "Severity": 50,
      "Id": 1
    },
    "ProjectName": "DotNetZip",
    "ReportedDate": "2011-08-24T07:28:54.833-07:00",
    "Status": {
      "Name": "Proposed",
      "Id": 1
    },
    "ReasonClosed": {
      "Name": "Unassigned"
    },
    "Summary": "Error using ZipFile.AddEntry(string, Stream)",
    "Type": {
      "Name": "Issue",
      "Id": 3
    },
    "VoteCount": 1,
    "Id": 14139
  },
  "FileAttachments": [
    {
      "FileId": 4052,
      "FileName": "ZipSource.zip",
      "DownloadUrl": ".\\4052"
    }
  ],
  "Comments": [
    {
      "Message": "replace \r\nzipFileJPGs.AddEntry(zipEntrySource.FileName, zipEntrySource.OpenReader());\r\nwith\r\nzipFileJPGs.AddEntry(zipEntrySource); \r\nand \r\nzipFileTXTs.AddEntry(zipEntrySource.FileName, zipEntrySource.OpenReader());\r\nwith\r\nzipFileTXTs.AddEntry(zipEntrySource);\r\nand this should work",
      "PostedDate": "2011-08-24T08:26:54.18-07:00",
      "Id": -2147483648
    },
    {
      "Message": "actually i am wrong with zipFileJPGs.AddEntry(zipEntrySource);\r\n\r\nbut your code works fine for me?",
      "PostedDate": "2011-08-24T08:36:38.68-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2011-08-24T10:55:59.673-07:00",
      "Id": -2147483648
    },
    {
      "Message": "It's strange... This works fine for very small files but with larger files, the error occurs. The attached file shows the case.",
      "PostedDate": "2011-08-24T10:56:01.83-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hi, you are correct. With you ZipSource.zip an error occurs. But guess what? You can workaround it easily... its the same bug again we seem to discover again and again.\r\nadd this to your code:\r\nzipFileTXTs.ParallelDeflateThreshold = -1;\r\nzipFileJPGs.ParallelDeflateThreshold = -1;\r\nbefore you call zipFileTXTs.Save(...);",
      "PostedDate": "2011-08-28T16:19:50.413-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Hello again folks!\r\n\r\nI have solved this issue with the following extension method:\r\n\r\n\n    public static class ZipFileExtensionMethods\n    {\n        public static ZipEntry AddEntry(this ZipFile zipFile, ZipEntry zipEntry)\n        {\n            using (MemoryStream ms = new MemoryStream((int)zipEntry.UncompressedSize))\n            {\n                zipEntry.Extract(ms);\r\n\r\n                return zipFile.AddEntry(zipEntry.FileName, ms.ToArray());\n            }\n        }\n    }\r\n\r\n\nSo the code above becomes:\r\n\r\n\n            using (ZipFile zipFileSource = ZipFile.Read(@\"D:\\Zips\\ZipSource.zip\"),\n                    zipFileJPGs = new ZipFile(),\n                    zipFileTXTs = new ZipFile())\n            {\n                foreach (ZipEntry zipEntrySource in zipFileSource)\n                {\n                    if (zipEntrySource.FileName.EndsWith(\"jpg\"))\n                    {\n                        zipFileJPGs.AddEntry(zipEntrySource);\n                    }\n                    else if (zipEntrySource.FileName.EndsWith(\"txt\"))\n                    {\n                        zipFileTXTs.AddEntry(zipEntrySource);\n                    }\n                }\r\n\r\n                zipFileJPGs.Save(@\"D:\\Zips\\ZipJPGs.zip\");\n                zipFileTXTs.Save(@\"D:\\Zips\\ZipTXTs.zip\");\n            }\r\n\r\n\nI really would like this issue in some new version of the component.\r\n\r\n\nThanks!",
      "PostedDate": "2012-10-25T04:44:59.493-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-02-21T18:43:04.363-08:00",
      "Id": -2147483648
    }
  ]
}