add brotli compression support

This commit is contained in:
Perfare 2018-03-05 05:07:41 +08:00
parent 8891414f60
commit 62206f8977
5 changed files with 40 additions and 6 deletions

View File

@ -394,7 +394,13 @@ namespace Unity_Studio
{
return FileType.WebFile;
}
reader.Position = 0x20;
magic = reader.ReadBytes(6);
reader.Position = 0;
if (WebFile.brotliMagic.SequenceEqual(magic))
{
return FileType.WebFile;
}
return FileType.AssetsFile;
}
}

View File

@ -4,12 +4,14 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using BrotliSharpLib;
namespace Unity_Studio
{
public class WebFile
{
public static byte[] gzipMagic = { 0x1f, 0x8b };
public static byte[] brotliMagic = { 0x62, 0x72, 0x6F, 0x74, 0x6C, 0x69 };
public List<MemoryFile> fileList = new List<MemoryFile>();
@ -28,9 +30,9 @@ namespace Unity_Studio
if (gzipMagic.SequenceEqual(magic))
{
var stream = new MemoryStream();
using (var gstream = new GZipStream(reader.BaseStream, CompressionMode.Decompress))
using (var gs = new GZipStream(reader.BaseStream, CompressionMode.Decompress))
{
gstream.CopyTo(stream);
gs.CopyTo(stream);
}
stream.Position = 0;
using (reader = new EndianBinaryReader(stream, EndianType.LittleEndian))
@ -39,11 +41,27 @@ namespace Unity_Studio
}
}
else
{
reader.Position = 0x20;
magic = reader.ReadBytes(6);
reader.Position = 0;
if (brotliMagic.SequenceEqual(magic))
{
var buff = reader.ReadBytes((int)reader.BaseStream.Length);
var uncompressedData = Brotli.DecompressBuffer(buff, 0, buff.Length);
var stream = new MemoryStream(uncompressedData);
using (reader = new EndianBinaryReader(stream, EndianType.LittleEndian))
{
ReadUnityWebData(reader);
}
}
else
{
reader.endian = EndianType.LittleEndian;
ReadUnityWebData(reader);
}
}
}
private void ReadUnityWebData(EndianBinaryReader reader)
{

View File

@ -55,6 +55,11 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="BrotliSharpLib, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\BrotliSharpLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\OpenTK.dll</HintPath>

View File

@ -55,6 +55,11 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="BrotliSharpLib, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\BrotliSharpLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\OpenTK.dll</HintPath>

Binary file not shown.