Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用SharpZipLib提取或访问gzip中特定文件的流?_C#_Compact Framework - Fatal编程技术网

C# 如何使用SharpZipLib提取或访问gzip中特定文件的流?

C# 如何使用SharpZipLib提取或访问gzip中特定文件的流?,c#,compact-framework,C#,Compact Framework,如何使用SharpZipLib从tar.gz(tar文件和文件夹,然后是gzip)提取特定文件(或具有流式访问权限)?或者任何人在.NET cf 3.5中都有类似的库来实现这一点?这应该可以为您实现 public static void Main(string[ args) { TarInputStream tarIn = new TarInputStream(new FileStream(@args[0], FileMode.Open, FileAccess.Read)); T

如何使用SharpZipLib从tar.gz(tar文件和文件夹,然后是gzip)提取特定文件(或具有流式访问权限)?或者任何人在.NET cf 3.5中都有类似的库来实现这一点?

这应该可以为您实现

public static void Main(string[ args)
{
    TarInputStream tarIn = new TarInputStream(new FileStream(@args[0], FileMode.Open, FileAccess.Read));
    TarEntry curEntry = tarIn.GetNextEntry();
    while (curEntry != null)
    {
        if (curEntry.Name.EndsWith("foo.txt", StringComparison.CurrentCultureIgnoreCase))
        {
            byte[] outBuffer = new byte[curEntry.Size];
            FileStream fs = new FileStream(@"foo.txt", FileMode.Create, FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(fs);
            tarIn.Read(outBuffer, 0, (int)curEntry.Size);
            bw.Write(outBuffer,0,outBuffer.Length);
            bw.Close();
        }
        curEntry = tarIn.GetNextEntry();
    }
    tarIn.Close();
}

您如何识别“Theonewant”条目?我想你得按名字找,还有别的办法吗?:)@Vijay通过使用TarEntry的任何属性(很可能是名称(或文件))现在都不太容易,可以吗这里的输出流是什么?它是如何初始化的?@SarangBorude outputStream可以是您可以写入的任何流,内存流或文件流。
using ( FileStream inputStream = File.OpenRead ( aPackage ) )
{
    using ( GzipInputStream gzStream = new GzipInputStream ( inputStream ) )
    {
        using ( TarInputStream tarStream = new TarInputStream ( gzStream ) )
        {
            TarEntry entry = tarStream.GetNextEntry();
            while ( entry != null )
            {
                if ( entry == theOneIWant )
                {
                    tarStream.CopyEntryContents (outputStream );
                    break;
                }
                entry = tarStream.GetNextEntry();
            }
        }
    }
}