zoukankan      html  css  js  c++  java
  • http解压缩gzip

    
            static async Task Main(string[] args)
            {
                var files = Directory.GetFiles("C:\Users\admin\Desktop\新建文件夹");
    
                foreach (string file in files)
                {
                    var src = await File.ReadAllBytesAsync(file);
                    ReadOnlySequence asMemory = new ReadOnlySequence(src.AsMemory());
                    ReadSession(ref asMemory, out _);
                    bool isgZip = false;
                    await using MemoryStream ms = new MemoryStream(asMemory.ToArray());
                    try
                    {
                        GZipStream gZip=new GZipStream(ms,CompressionMode.Decompress);
                        await using MemoryStream destStream=new MemoryStream();
                        await gZip.CopyToAsync(destStream);
                        var destBytes = destStream.ToArray();
                        await File.WriteAllBytesAsync(file+"gzip1.txt",destBytes);
                        isgZip = true;
                    }
                    catch (Exception e)
                    {
                        
                    }
    
                    if (!isgZip)
                    {
                        await File.WriteAllBytesAsync(file + "gzip0.txt", asMemory.ToArray());
                    }
    
    
                }
            }
    
            public static bool ReadSession(ref ReadOnlySequence buffer,
                out ReadOnlySequence request)
            {
                ReadOnlySpan newSplit = new[] { (byte)'
    ', (byte)'
    ' , (byte)'
    ', (byte)'
    ' };
                var reader = new SequenceReader(buffer);
                if (reader.TryReadTo(out request, newSplit))
                {
                    buffer = buffer.Slice(reader.Position);
                    return true;
                }
                request = default;
                return false;
    
            }
    
  • 相关阅读:
    转:Jenkins自动化部署入门详细教程
    详解MySQL锁
    常见的内存溢出与解决办法
    read IEEE Standard for verilog(1)
    verilog之状态机
    quantus18的signaltap逻辑分析仪
    英语文档之关键词统计
    cadence软件画版图操作
    英语文档之vivado界面
    verilog之wire和reg
  • 原文地址:https://www.cnblogs.com/yzpopulation/p/13996049.html
Copyright © 2011-2022 走看看