When using ICSharpCode.SharpZipLib to decompress BZip2 files I am having an issue where only the first 900,000 uncompressed bytes are extracted. I've tried both the BZip2InputStream and the BZip2.Decompress static method to no avail. The compressed data is 8,518 bytes which I have confirmed is the length of the byte array that I pass in as compressedDataByteArray, and the decompressed data should be 1,134,592 bytes - so I can see that it is being truncated.
My attempt with BZip2InputStream - observe that the console writes out "900000" instead of "1134592":
static void Main(string[] args)
{
var compressedDataByteArray = File.ReadAllBytes("data.bz2");
using (var mstream = new MemoryStream(compressedDataByteArray))
using (var zstream = new BZip2InputStream(mstream))
using (var reader = new StreamReader(zstream))
{
string uncompressedData = reader.ReadToEnd();
Console.WriteLine(uncompressedData.Length);
}
Console.ReadKey();
}
Alternatively, I have tried the BZip2.Decompress method - observe that the console also writes out "900000" instead of "1134592":
static void Main(string[] args)
{
var compressedDataByteArray = File.ReadAllBytes("data.bz2");
using (var indata = new MemoryStream(compressedDataByteArray))
using (var outdata = new MemoryStream())
{
BZip2.Decompress(indata, outdata, false);
string uncompressedData = Encoding.UTF8.GetString(outdata.ToArray());
Console.WriteLine(uncompressedData.Length);
}
Console.ReadKey();
}
Is there some flag or option I am missing? Does the library need to be licensed? I'm not clear why the uncompressed data always stops there. For reference I am using #SharpZipLib 1.3.0 Nuget package
Here is the bz2 file I am using: https://drive.google.com/uc?id=1CD0XnJjAITxIrBqD90Msnygc4xnDXk5X&export=download
Evidently, it may be a shortcoming with the SharpZipLib, so I migrated to SharpCompress and it now works as expected:
Much thanks to @CodeCaster.