So I need to decompress a BZip2-file, use the files data, and then remove the decompressed file. The issue is that my method doesn't work when the BZip2-file is too large.
Been using:
using ICSharpCode.SharpZipLib.BZip2;
This is what I've been trying to do:
private List<JObject> listWithObjects;
private void DecompressBzip2File(string bzipPath)
{
string tempPath = Path.GetRandomFileName();
FileStream fs = new FileStream(bzipPath, FileMode.Open);
using (FileStream decompressedStream = File.Create(tempPath))
{
BZip2.Decompress(fs, decompressedStream, true);
}
LoadJson(tempPath);
File.Delete(tempPath);
}
private void LoadJson(string tempPath)
{
List<JObject> jsonList = new List<JObject>();
using (StreamReader file = new StreamReader(tempPath))
{
string line;
while ((line = file.ReadLine()) != null)
{
JObject jObject = JObject.Parse(line);
jsonList.Add(jObject);
}
file.Close();
}
listWithObjects = jsonList;
}
It's working when I've got a .bz2 ~14mb, but not when I've tried a .bz2 ~900mb my program just stops (and I get no error-message(my RAM goes crazy)). I read something about buffer size, but couldn't figure out how to use it.
Does anyone have any tip on how I could decompress a large bzip2-file? Could you like chunk the file to smaller pieces?