解压缩大型BZip2文件 - C#

时间:2017-12-14 12:19:30

标签: c# compression bzip2

所以我需要解压缩BZip2文件,使用文件数据,然后删除解压缩的文件。问题是当BZip2文件太大时我的方法不起作用。

一直在使用:

using ICSharpCode.SharpZipLib.BZip2;

这就是我一直在尝试做的事情:

    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;
    }

当我有一个.bz2~14mb的时候它正在工作,但是当我尝试了.bz2~900mb时,我的程序就停止了(我没有收到任何错误消息(我的) RAM变得疯狂))。我读了一些关于缓冲区大小的内容,但无法弄清楚如何使用它。

有没有人对如何解压缩大型bzip2文件有任何提示?你能不能把文件分成小块?

0 个答案:

没有答案
相关问题