合并 7z 档案

合并 7z 档案

我尝试下载 7z 存档两次,但两次都没有完全下载。所以我有 2 个部分下载的 2GB 文件,根据下载管理器程序中的下载段图,应该可以将它们合并为一个完整的文件。
所以我想知道最好的方法是什么?
提前谢谢!

答案1

我希望你能告诉我一个可以解决问题的程序名,在等待答案的时候,我自己创建了一个这样的程序。简单代码(C#):

static void Main(string[] args)
{
    int fails = 0;
    long failStart = 0;
    long failEnd = 0;

    const string fileWithHole = @"c:\Downloads\1\eveonline_395875_1of2.7z";
    const string fileFilledWhereHole = @"c:\Downloads\eveonline_395875_1of2.7z";

    // Copy of the 1st one to repair the hole:
    const string targetFile = @"d:\Eve\eveonline_395875_1of2.7z";

    using (var br = new BinaryReader(new FileStream(fileWithHole, FileMode.Open)))
    {
        long pos = 0;
        long len = br.BaseStream.Length;

        using (var br1 = new BinaryReader(new FileStream(fileFilledWhereHole, FileMode.Open)))
        {
            using (var w = File.OpenWrite(targetFile))
            {
                // As I know that hole is in the 1st half of file:
                while (pos < len/2)
                {
                    byte b = br.ReadByte();
                    byte b1 = br1.ReadByte();

                    // 1 MB to log:
                    if (pos%1000000 == 0)
                    {
                        Console.Clear();
                        Console.WriteLine("{0} MB", pos/1000000);
                        Console.WriteLine("FAILS: {0}", fails);
                        Console.WriteLine("FROM {0} TO {1}", failStart, failEnd);
                    }

                    if (b != b1)
                    {
                        fails++;

                        if (failStart == 0)
                        {
                            failStart = pos;
                            w.Seek(pos, SeekOrigin.Begin);
                        }
                        failEnd = pos;

                        // Repair the hole in copied file:
                        w.WriteByte(b);
                    }

                    pos++;
                }
            }
        }
    }
}

相关内容