shoko/Media/GzipMediaHandler.cs

40 lines
927 B
C#
Raw Normal View History

2023-10-20 04:59:28 +00:00
using System.IO.Compression;
using HeyRed.Mime;
namespace Shoko;
[MediaType("application/gzip")]
class GzipMediaHandler : MediaHandler
{
MediaHandler newHandler;
public GzipMediaHandler(ProtoHandler content)
{
Content = content;
}
public override async Task Load()
{
var stream = new GZipStream(Content.Content, CompressionMode.Decompress);
var mem = new MemoryStream();
await stream.CopyToAsync(mem);
mem.Position = 0;
Content.MediaType = MimeGuesser.GuessMimeType(mem);
Content.Content = mem;
newHandler = GetHandler(Content);
await newHandler.Load();
OnLoaded();
}
public override void Render()
{
2023-10-20 05:41:54 +00:00
if(newHandler?.IsLoaded ?? false)
newHandler.Render();
2023-10-20 04:59:28 +00:00
}
public override void MenuBar()
{
2023-10-20 05:41:54 +00:00
if(newHandler?.IsLoaded ?? false)
newHandler.MenuBar();
2023-10-20 04:59:28 +00:00
}
}