Пример #1
0
 private static async ValueTask <ImmutableArray <SourceFileInfo> > LoadSourceFiles(ImmutableDictionary <string, string> metadata)
 {
     foreach (var p in metadata)
     {
         var keyArray = p.Key.Split('.');
         if (keyArray.Length >= 2 &&
             keyArray[1] == "EmbeddedSourceCode")
         {
             SourceFileInfo[]? embedded;
             if (Array.IndexOf(keyArray, "GZipBase32768", 2) >= 0)
             {
                 using var ms = new MemoryStream(Base32768.Decode(p.Value));
                 using var gz = new GZipStream(ms, CompressionMode.Decompress);
                 embedded     = await JsonSerializer.DeserializeAsync <SourceFileInfo[]>(gz).ConfigureAwait(false);
             }
             else
             {
                 embedded = JsonSerializer.Deserialize <SourceFileInfo[]>(p.Value);
             }
             if (embedded is not null)
             {
                 return(ImmutableArray.Create(embedded));
             }
         }
     }
     return(ImmutableArray <SourceFileInfo> .Empty);
 }
        public static MemoryStream FromGZipBase32768ToStream(string compressed)
        {
            using var msIn = new MemoryStream(Base32768.Decode(compressed));
            var msOut = new MemoryStream();

            using (var gz = new GZipStream(msIn, CompressionMode.Decompress))
                gz.CopyTo(msOut);
            msOut.Position = 0;
            return(msOut);
        }