Sanity checks before writing

This commit is contained in:
Matt Nadareski
2024-04-25 14:30:28 -04:00
parent 4bffd9d31c
commit fbbe77f5f2
2 changed files with 8 additions and 0 deletions

View File

@@ -410,6 +410,10 @@ namespace SabreTools.IO.Extensions
/// </summary>
private static bool WriteFromBuffer(BinaryWriter writer, byte[] value)
{
// If the stream is not writable
if (!writer.BaseStream.CanWrite)
return false;
// Handle the 0-byte case
if (value.Length == 0)
return true;

View File

@@ -408,6 +408,10 @@ namespace SabreTools.IO.Extensions
/// </summary>
private static bool WriteFromBuffer(Stream stream, byte[] value)
{
// If the stream is not writable
if (!stream.CanWrite)
return false;
// Handle the 0-byte case
if (value.Length == 0)
return true;