38 lines
835 B
C#
38 lines
835 B
C#
|
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()
|
||
|
{
|
||
|
newHandler.Render();
|
||
|
}
|
||
|
|
||
|
public override void MenuBar()
|
||
|
{
|
||
|
newHandler.MenuBar();
|
||
|
}
|
||
|
}
|