{
  "WorkItem": {
    "AffectedComponent": {
      "Name": "",
      "DisplayName": ""
    },
    "ClosedComment": "Not a bug.Thanks for confirming that it works for you.",
    "ClosedDate": "2009-11-10T01:15:15.887-08:00",
    "CommentCount": 0,
    "Custom": null,
    "Description": "I just tried to perform full in-memory editing of a zip file (unittest, similar to the real code for later):\n1) Create a Zip-File with some fake entries using ZipFile..ctor() and ZipFile.AddEntry(string, string, byte[]).\n2) Attempt to modify one of the file entries using ZipEntry.Extract(Stream) and ZipFile.UpdateEntry(string, string, byte[]).\n3) Obtain a byte[] again by calling ZipFile.Save(Stream) and send it somewhere else.\n \nMy first attempt failed at point 2, since Extract(Stream) does not work when the file was not saved before.\nInserting a call to ZipFile.Save(string) before calling Extract works fine, but writing to the filesystem should be avoided in this case (at best).\nCalling ZipFile.Save(Stream) instead and ignoring the stream at all (just to be able to use Extract) causes a NullReferenceException to be raised.\n \nExample Code:\nZipFile zip = new ZipFile()\nzip.AddEntry(entryName, \"\", \"fake content\");\nvar entry = zip[entryName];\n \nstring fileContent = string.Empty;\nusing (var ms = new MemoryStream())\n{\n   zip.Save(ms); //ignore result\n   //zip.Save(@\"C:\\tmp.zip\"); //works, but should be avoided in my case\n   fosi.Extract(ms); //exception here\n   content = ms.ToArray();\n}\ncontent = ModifyFileContent(content);\nzip.UpdateEntry(stylesheet.Name, \"\", content);\nusing (var ms = new MemoryStream())\n{\n   zip.Save(ms);\n   content = ms.ToArray();\n}\nDoStuffWithContent(content);\n \nThe NullReferenceException is raised since zf.ReadStream in ZipFile.Read.cs:987 is null when calling s.CanSeek a few lines later.\n \nUsed version is the official 1.8 release v1.8.4.27",
    "LastUpdatedDate": "2013-05-16T05:31:59.917-07:00",
    "PlannedForRelease": "",
    "ReleaseVisibleToPublic": false,
    "Priority": {
      "Name": "Low",
      "Severity": 50,
      "Id": 1
    },
    "ProjectName": "DotNetZip",
    "ReportedDate": "2009-11-09T07:35:44.89-08:00",
    "Status": {
      "Name": "Closed",
      "Id": 4
    },
    "ReasonClosed": {
      "Name": "Unassigned"
    },
    "Summary": "In-Memory editing fails with NullReferenceException (ZipFile.Read, ReadToInstance)",
    "Type": {
      "Name": "Issue",
      "Id": 3
    },
    "VoteCount": 1,
    "Id": 9149
  },
  "FileAttachments": [],
  "Comments": [
    {
      "Message": "I don't know what you're trying to do, but there's a simpler way. \r\n\r\n        {\r\n            string entryName = \"zipentry.xx\";\r\n            byte[] zipFileContent= null;\r\n            byte[] entryContent = null;\r\n            using (var ms = new MemoryStream())\r\n            {\r\n                using (ZipFile zip = new ZipFile())\r\n                {\r\n                    zip.AddEntry(entryName, \"fake content\");\r\n                    var entry = zip[entryName];\r\n                    zip.Save(ms); // save into memory\r\n                }\r\n\r\n                // put the zipfile content into a byte array\r\n                zipFileContent = ms.ToArray();\r\n\r\n                // now, read the in-memory zipfile\r\n                using (ZipFile zip = ZipFile.Read(zipFileContent))\r\n                {\r\n                    entryContent = zip[entryName].OpenReader().ReadAllBytes();\r\n                    // do whatever you want with the entry content\r\n                }\r\n            }\r\n        }        \r\n\r\nI suggest the forums if you want to talk about it. \r\n",
      "PostedDate": "2009-11-09T14:29:15.89-08:00",
      "Id": -2147483648
    },
    {
      "Message": "As said, I'd like to perform full in-memory editing of a zip file, without writing it to a file first.\r\n\r\nI didn't know about OpenReader(), it seems to work as expected. Thanks for the pointer.\r\n\r\nHowever, I think there should be some sort of test or example project that illustrates this (unless I missed it completely).\r\nAlso, it's a bit odd that I cannot simply get the contents back without calling Save first, it's like \"I just stuffed in a string, why can I save/read/get it, but not get it right away?\".\r\n\r\nOther than that, I guess this case could be marked as closed or the likes, even tho the NullReferenceException still exists in there and should be checked for.",
      "PostedDate": "2009-11-09T23:40:33.78-08:00",
      "Id": -2147483648
    },
    {
      "Message": "The Save() is required because it is. That's just how the ZipFile class works. It doesn't actually do any compression until you call Save().  This is documented pretty much everywhere.  If you want a stream, you can try ZipOutputStream.  That compresses as it goes.  But it is output only, you may not read from that stream.  \r\n\r\nA NullPointerException is bad, but your code was doing some odd things with the streams.  When I unraveled it, I didn't see the error.  so I chalked that up to usage.  \r\n\r\n ",
      "PostedDate": "2009-11-10T01:14:51.687-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-11-10T01:15:15.887-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-02-21T18:43:48.93-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-05-16T05:31:59.917-07:00",
      "Id": -2147483648
    }
  ]
}