Skip to content

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

@doggy8088

Description

@doggy8088

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
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions