[
  {
    "Id": "1429398",
    "ThreadId": "639606",
    "Html": "Hi,\r<br />\n<br />\nI have File with 10 line, I'm compressing to Bz2 Format, But when i decompress it, I see generated File has only 9 line. There is data loss of 1.5 line. Here is my Code for compressing to Bz2\r<br />\n<br />\nFollowing is the code for compression, I'm converting file to UTF-8 and Bz2 File.<br />\n<pre><code> static string Compress(string sourceFile, bool forceOverwrite)\n        {\n            var outFname = fname + &quot;.bz2&quot;;\n           \n            if (File.Exists(outFname))\n            {\n                if (forceOverwrite)\n                    File.Delete(outFname);\n                else\n                    return null;\n            }\n            long rowCount = 0;\n            var output = File.Create(outFname);\n\n            try\n            {\n                  using (StreamReader reader = new StreamReader(fname))\n                {\n                    using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output))\n                    {\n                        StreamWriter writer = new StreamWriter(compressor, System.Text.Encoding.UTF8);\n                         string line = &quot;&quot;;\n                        while ((line = reader.ReadLine()) != null)\n                        {\n                            writer.WriteLine(line);\n                            rowCount++;\n\n                            if (rowCount % 100000 == 0)\n                                Console.WriteLine(&quot;InProgress..Current Row # &quot; + rowCount.ToString());\n                        }\n\n                    }\n                }\n            }\n            catch (Exception)\n            {\n\n                throw;\n            }\n            finally\n            {\n                if (output != null)\n                    output = null;\n            }\n\n            //     Pump(fs, compressor);\n\n            return outFname;\n        }\n</code></pre>\n\nI tired to change read method like below<br />\n<pre><code>                // int charsRead;\n                        // char[] buffer = new char[2048];\n                        // while ((charsRead = reader.ReadBlock(buffer, 0, buffer.Length)) &gt; 0)\n                        // {\n                        //     writer.Write(buffer, 0, charsRead);\n                        //     rowCount++;\n\n                        //     if (rowCount % 100000 == 0)\n                        //         Console.WriteLine(&quot;InProgress..Current Row # &quot; + rowCount.ToString());\n                        // }\n</code></pre>\n\nFor Decompression,\r<br />\nhere is the code<br />\n<pre><code> public static string Decompress(string fname, bool forceOverwrite)\n        {\n            var outFname = Path.GetFileNameWithoutExtension(fname);\n            if (File.Exists(outFname))\n            {\n                if (forceOverwrite)\n                    File.Delete(outFname);\n                else\n                    return null;\n            }\n\n            using (Stream fs = File.OpenRead(fname),\n                   output = File.Create(outFname),\n                   decompressor = new Ionic.BZip2.BZip2InputStream(fs))\n                Pump(decompressor, output);\n\n            return outFname;\n        }\n private static void Pump(Stream src, Stream dest)\n        {\n            byte[] buffer = new byte[2048];\n            int n;\n            while ((n = src.Read(buffer, 0, buffer.Length)) &gt; 0)\n                dest.Write(buffer, 0, n);\n\n        }\n\n</code></pre>\n\nDuring debugging, I see readline is reading data correctly, not sure whether it is bug in this library dll in convert actual file to Bz2 or reading from Bz2 . Please let me know reason for this issue<br />\n",
    "PostedDate": "2015-06-06T14:59:12.22-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]