-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2378 from JsphA/master
Add kernel compression
- Loading branch information
Showing
4 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IO; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using System.IO.Compression; | ||
using System.Diagnostics; | ||
|
||
namespace Cosmos.Build.Tasks | ||
{ | ||
public class Gzip : Task | ||
{ | ||
[Required] | ||
public string BinFile { get; set; } | ||
|
||
[Required] | ||
public string OutputFile { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
if (!File.Exists(BinFile)) | ||
{ | ||
Log.LogError($"'{BinFile}' is missing!"); | ||
return false; | ||
} | ||
|
||
var stopwatch = new Stopwatch(); | ||
stopwatch.Start(); | ||
|
||
using FileStream fileStream = File.Open(BinFile, FileMode.Open); | ||
using FileStream compressedFileStream = File.Create(OutputFile); | ||
using var gzip = new GZipStream(compressedFileStream, CompressionLevel.Optimal); | ||
fileStream.CopyTo(gzip); | ||
|
||
stopwatch.Stop(); | ||
|
||
int beforeMB = (int)(new FileInfo(BinFile).Length / 1024 / 1024); | ||
int afterMB = (int)(new FileInfo(OutputFile).Length / 1024 / 1024); | ||
|
||
Log.LogMessage(MessageImportance.High, $"Compressed '{BinFile}' with gzip in {stopwatch.ElapsedMilliseconds} ms ({beforeMB} MB -> {afterMB} MB)"); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters