From beb1a8fc843c4d99755f87121f36eea01659db0c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 15 Sep 2024 22:57:16 +0300 Subject: [PATCH] Do not close stream after deserializing text kv1 Fixes #104 --- .../ValveKeyValue.Test/Text/StreamsTestCase.cs | 10 ++++++++++ ValveKeyValue/ValveKeyValue/KVSerializer.cs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ValveKeyValue/ValveKeyValue.Test/Text/StreamsTestCase.cs b/ValveKeyValue/ValveKeyValue.Test/Text/StreamsTestCase.cs index 031df604..15fb4434 100644 --- a/ValveKeyValue/ValveKeyValue.Test/Text/StreamsTestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/Text/StreamsTestCase.cs @@ -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); + } } diff --git a/ValveKeyValue/ValveKeyValue/KVSerializer.cs b/ValveKeyValue/ValveKeyValue/KVSerializer.cs index 35fac7fc..72db7638 100644 --- a/ValveKeyValue/ValveKeyValue/KVSerializer.cs +++ b/ValveKeyValue/ValveKeyValue/KVSerializer.cs @@ -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."), };