Serialize JSON a slightly different way

This commit is contained in:
Matt Nadareski
2025-05-12 21:44:47 -04:00
parent e5bcada606
commit 4016b3fc19
2 changed files with 8 additions and 6 deletions

View File

@@ -49,6 +49,7 @@
- One more note about hidden settings
- Explicitly unset Redumper speed, if needed
- Simplify WriteOutputData path handling
- Serialize JSON a slightly different way
### 3.3.0 (2025-01-03)

View File

@@ -743,10 +743,6 @@ namespace MPF.Frontend
try
{
// Serialize the JSON and get it writable
string json = JsonConvert.SerializeObject(info, Formatting.Indented);
byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
// Get the output path
var path = string.Empty;
if (string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix))
@@ -765,15 +761,20 @@ namespace MPF.Frontend
// Create and open the output file
using var fs = File.Create(path);
// Create the JSON serializer
var serializer = new JsonSerializer { Formatting = Formatting.Indented };
// If we included artifacts, write to a GZip-compressed file
if (includedArtifacts)
{
using var gs = new GZipStream(fs, CompressionMode.Compress);
gs.Write(jsonBytes, 0, jsonBytes.Length);
using var sw = new StreamWriter(gs, Encoding.UTF8);
serializer.Serialize(sw, info);
}
else
{
fs.Write(jsonBytes, 0, jsonBytes.Length);
using var sw = new StreamWriter(fs, Encoding.UTF8);
serializer.Serialize(sw, info);
}
}
catch