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