Skip to content

Commit

Permalink
Do not close stream after deserializing text kv1
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
xPaw committed Sep 15, 2024
1 parent baff467 commit beb1a8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/Text/StreamsTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ public void CanHandleBlockingStreams(int maxReadAtOnce)

Assert.That(data["test"].ToInt32(CultureInfo.InvariantCulture), Is.EqualTo(1337));
}

[Test]
public void LeavesStreamOpenAfterDeserialize()
{
using var stream = TestDataHelper.OpenResource("Text.object_person.vdf");

KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);

Assert.That(stream.CanRead, Is.True);
}
}
2 changes: 1 addition & 1 deletion ValveKeyValue/ValveKeyValue/KVSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ IVisitingReader MakeReader(Stream stream, IParsingVisitationListener listener, K

return format switch
{
KVSerializationFormat.KeyValues1Text => new KV1TextReader(new StreamReader(stream), listener, options),
KVSerializationFormat.KeyValues1Text => new KV1TextReader(new StreamReader(stream, null, true, -1, leaveOpen: true), listener, options),
KVSerializationFormat.KeyValues1Binary => new KV1BinaryReader(stream, listener, options.StringTable),
_ => throw new ArgumentOutOfRangeException(nameof(format), format, "Invalid serialization format."),
};
Expand Down

0 comments on commit beb1a8f

Please sign in to comment.