compress parsed data to .json.zst
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Text.Encodings.Web;
|
||||
using System.Text.Json.Serialization;
|
||||
using ParadoxSaveParser.WebAPI.Database;
|
||||
using ParadoxSaveParser.WebAPI.SaveDataFilters;
|
||||
using ZstdSharp;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI.BackgroundTasks;
|
||||
|
||||
@@ -13,6 +14,7 @@ public class SaveParsingOperation
|
||||
private readonly SaveFileMetadata _meta;
|
||||
private readonly ISaveDataFilter _filter;
|
||||
private readonly long _maxGameDataBytes;
|
||||
private readonly int _zstdCompressionLevel;
|
||||
private readonly ContextLogger _logger;
|
||||
private readonly CancellationToken _ct;
|
||||
|
||||
@@ -25,12 +27,13 @@ public class SaveParsingOperation
|
||||
};
|
||||
|
||||
public SaveParsingOperation(long operationId, SaveFileMetadata meta, ISaveDataFilter filter,
|
||||
long maxGameDataBytes, ContextLogger logger, CancellationToken ct)
|
||||
long maxGameDataBytes, int zstdCompressionLevel, ContextLogger logger, CancellationToken ct)
|
||||
{
|
||||
OperationId = operationId;
|
||||
_meta = meta;
|
||||
_filter = filter;
|
||||
_maxGameDataBytes = maxGameDataBytes;
|
||||
_zstdCompressionLevel = zstdCompressionLevel;
|
||||
_logger = logger;
|
||||
_ct = ct;
|
||||
}
|
||||
@@ -90,7 +93,11 @@ public class SaveParsingOperation
|
||||
await Program.DB.UpdateMetadataStatus(_meta, SaveFileProcessingStatus.SavingResults);
|
||||
var resultFilePath = _meta.GetParsedDataPath();
|
||||
await using (var resultFile = File.OpenWrite(resultFilePath))
|
||||
await JsonSerializer.SerializeAsync(resultFile, parsedData, _jsonOptions, _ct);
|
||||
{
|
||||
// the zstd frame is finished only when compression stream is disposed, so it must happen before Done
|
||||
await using var zstd = new CompressionStream(resultFile, _zstdCompressionLevel);
|
||||
await JsonSerializer.SerializeAsync(zstd, parsedData, _jsonOptions, _ct);
|
||||
}
|
||||
await Program.DB.UpdateMetadataStatus(_meta, SaveFileProcessingStatus.Done);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user