Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush the writer when a full object is written #717

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

dgileadi
Copy link
Contributor

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.

@joethephish joethephish merged commit 8a491db into inkle:master Jun 5, 2024
@joethephish
Copy link
Member

3 years later... thank you! What is even time

@dgileadi dgileadi deleted the flush-json branch June 5, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants