ink
ink copied to clipboard
Flush the writer when a full object is written
When writing a large amount of JSON to a StreamWriter it's possible for the JSON to get truncated because the writer is never flushed before it's closed. This PR changes SimpleJson to flush whenever the end of an object is written and the state stack becomes empty.
To reproduce the truncation (before this change) you can do:
using (var stream = File.Open(jsonFilePath), FileMode.Create))
{
story.ToJson(stream);
}
On my box my particular ink script results in a truncated JSON file a bit longer than 5,000 chars. After the fix it results in a complete JSON file over 6,000 chars.