Skip to content

Commit 15b12eb

Browse files
committed
Dispose хеш-провайдера и мелочи
1 parent 6451163 commit 15b12eb

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/OneScript.StandardLibrary/Hash/HashImpl.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This Source Code Form is subject to the terms of the
1919
namespace OneScript.StandardLibrary.Hash
2020
{
2121
[ContextClass("ХешированиеДанных", "DataHashing")]
22-
public class HashImpl : AutoContext<HashImpl>
22+
public class HashImpl : AutoContext<HashImpl>, IDisposable
2323
{
2424
private const int BUFFER_SIZE = (1024 * 32);
2525

@@ -131,7 +131,7 @@ public void Append(BslValue toAdd, int count = 0)
131131
if (count <= 0)
132132
AppendStream(stream);
133133
else
134-
AppendStream(stream, count);
134+
AppendStream(stream, count);
135135
break;
136136
case BinaryDataContext binaryData:
137137
AppendStream(binaryData.GetStream());
@@ -147,11 +147,8 @@ public void AppendFile(string path)
147147
if (!File.Exists(path))
148148
throw RuntimeException.InvalidArgumentType();
149149

150-
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
151-
{
152-
AppendStream(stream);
153-
stream.Close();
154-
}
150+
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
151+
AppendStream(stream);
155152
}
156153

157154
[ScriptConstructor(Name = "По указанной хеш-функции")]
@@ -175,7 +172,11 @@ private static HashAlgorithmName GetAlgorithmName(HashFunctionEnum algo)
175172
HashFunctionEnum.SHA512 => HashAlgorithmName.SHA512,
176173
_ => throw RuntimeException.InvalidArgumentValue()
177174
};
175+
}
176+
177+
public void Dispose()
178+
{
179+
_provider?.Dispose();
178180
}
179-
180181
}
181182
}

tests/datahashing-from-stream.os

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
, НРег(ПолучитьHexСтрокуИзДвоичныхДанных(Хеширование.ХешСумма)));
5959

6060
Хеширование.Добавить(ФайловыйПоток, 12);
61-
Сообщить(Хеширование.ХешСуммаСтрокой);
6261
юТест.ПроверитьРавенство("3bc6abfa41bb73c8bcc4c0f5f4d4db42f10f38295a0432afc592fe998465cb9a"
6362
, НРег(ПолучитьHexСтрокуИзДвоичныхДанных(Хеширование.ХешСумма)));
6463

0 commit comments

Comments
 (0)