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

The TextWriter writer should not be closed in the WriteStream method #39

Open
doggy8088 opened this issue Feb 15, 2024 · 1 comment
Open

Comments

@doggy8088
Copy link

The WriteStream in the SrtWriter method might called multiple times. I think the TextWriter writer should not be closed early in this method.

public void WriteStream(Stream stream, IEnumerable<SubtitleItem> subtitleItems, bool includeFormatting = true)
{
using TextWriter writer = new StreamWriter(stream);
List<SubtitleItem> items = subtitleItems.ToList(); // avoid multiple enumeration since we're using a for instead of foreach
for (int i = 0; i < items.Count; i++)
{
SubtitleItem subtitleItem = items[i];
IEnumerable<string> lines = SubtitleItemToSubtitleEntry(subtitleItem, i + 1, includeFormatting); // add one because subtitle entry numbers start at 1 instead of 0
foreach (string line in lines)
writer.WriteLine(line);
writer.WriteLine(); // empty line between subtitle entries
}
}

@AlexPoint
Copy link
Owner

Good catch!
Indeed, the TextWriter object should be closed to avoid any issue.
Could you submit a fix so that I can package a corrective version?

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

No branches or pull requests

2 participants