如何将 gzip 压缩文件转换为 Zstandard

How to convert from a gzip compressed file to Zstandard

如何将 gzip 压缩文件转换为 Zstandard?这是我的尝试:

using Zstandard.Net;

public static void ConvertToZstd(string path)
{
    byte[] compressed = null;
    using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
    using (var gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
    using (var memoryStream = new MemoryStream())
    using (var compressionStream = new ZstandardStream(memoryStream, CompressionMode.Compress))
    {
        compressionStream.CompressionLevel = 11;               // optional!!
        //compressionStream.CompressionDictionary = dictionary;  // optional!!
        compressionStream.Write(gzipStream, 0, gzipStream.Length);
        compressionStream.Close();
        compressed = memoryStream.ToArray();
    }
}
public static void ConvertToZstd(string path, string outputPath)
{
    using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
    using (var gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
    using (var memoryStream = new MemoryStream())
    using (var compressionStream = new ZstandardStream(memoryStream, CompressionMode.Compress))
    {
        compressionStream.CompressionLevel = 11;               // optional!!
        //compressionStream.CompressionDictionary = dictionary;  // optional!!
        gzipStream.CopyTo(compressionStream);
        compressionStream.Close();
        File.WriteAllBytes(outputPath, memoryStream.ToArray());
    }
}