如何在C#中解压缩.bz2文件? - c#

我正在开发WPF应用程序。我正在使用Sharpziplib压缩和解压缩文件。我很容易使用以下代码解压缩.zip文件

public static void UnZip(string SrcFile, string DstFile, string safeFileName, int bufferSize)
        {
            //ICSharpCode.SharpZipLib.Zip.UseZip64.Off;

            FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
            ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);


            string rootDirectory = string.Empty;
            if (safeFileName.Contains(".zip"))
            {
                rootDirectory = safeFileName.Replace(".zip", string.Empty);
            }
            else
            {
                rootDirectory = safeFileName;
            }

            Directory.CreateDirectory(App.ApplicationPath + rootDirectory);

            while (true)
            {
                ZipEntry entry = zipInStream.GetNextEntry();

                if (entry == null)
                    break;

                if (entry.Name.Contains("/"))
                {
                    string[] folders = entry.Name.Split('/');

                    string lastElement = folders[folders.Length - 1];
                    var folderList = new List<string>(folders);
                    folderList.RemoveAt(folders.Length - 1);
                    folders = folderList.ToArray();

                    string folderPath = "";
                    foreach (string str in folders)
                    {
                        folderPath = folderPath + "/" + str;
                        if (!Directory.Exists(App.ApplicationPath + rootDirectory + "/" + folderPath))
                        {
                            Directory.CreateDirectory(App.ApplicationPath + rootDirectory + "/" + folderPath);
                        }
                    }

                    if (!string.IsNullOrEmpty(lastElement))
                    {
                        folderPath = folderPath + "/" + lastElement;
                        WriteToFile(DstFile + rootDirectory + @"\" + folderPath, bufferSize, zipInStream, rootDirectory, entry);
                    }

                }
                else
                {
                    WriteToFile(DstFile + rootDirectory + @"\" + entry.Name, bufferSize, zipInStream, rootDirectory, entry);
                }
            }

            zipInStream.Close();           
            fileStreamIn.Close();
        }

        private static void WriteToFile(string DstFile, int bufferSize, ZipInputStream zipInStream, string rootDirectory, ZipEntry entry)
        {
            FileStream fileStreamOut = new FileStream(DstFile, FileMode.OpenOrCreate, FileAccess.Write);
            int size;
            byte[] buffer = new byte[bufferSize];

            do
            {
                size = zipInStream.Read(buffer, 0, buffer.Length);
                fileStreamOut.Write(buffer, 0, size);
            } while (size > 0);

            fileStreamOut.Close();
        }

但是,相同的代码不适用于.bz2文件。它在行上给出错误

ZipEntry entry = zipInStream.GetNextEntry();

错误是-错误的本地标头签名:0x26594131。我应该如何解压缩.bz2文件?您能否提供任何可解决上述问题的代码或链接?

参考方案

当对ZipInputStream文件使用.zip时,对于BZip2InputStream文件应使用.bz2(对于GZipInputStream文件等应使用.gz。)。

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

改造正在返回一个空的响应主体 - java

我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…

每个文件合并后添加换行 - python

我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…

Json到php,json_decode返回NULL - php

我正在用PHP进行JSON解析器的一些API,用于存储有关遗产的信息。我在解析时遇到问题,因为它返回的是NULL值而不是数组或对象。简单的JSON代码可以很好地解析,但是可以这样:{"success":true,"totalCount":1,"data":[{"id":99694…

您如何在列表内部调用一个字符串位置? - python

我一直在做迷宫游戏。我首先决定制作一个迷你教程。游戏开发才刚刚开始,现在我正在尝试使其向上发展。我正在尝试更改PlayerAre变量,但是它不起作用。我试过放在列表内和列表外。maze = ["o","*","*","*","*","*",…