From 990e63543d8526459fb2ee8411ca824f4555a42e Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Sun, 18 Feb 2024 22:45:22 +1100 Subject: [PATCH] Use spans in readers in .NET 8 Update the conditional symbols. --- MetadataExtractor/IO/IndexedSeekingReader.cs | 5 ++--- MetadataExtractor/IO/SequentialStreamReader.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/MetadataExtractor/IO/IndexedSeekingReader.cs b/MetadataExtractor/IO/IndexedSeekingReader.cs index ae27d06f9..153c69d2e 100644 --- a/MetadataExtractor/IO/IndexedSeekingReader.cs +++ b/MetadataExtractor/IO/IndexedSeekingReader.cs @@ -41,7 +41,7 @@ public IndexedSeekingReader(Stream stream, int baseOffset = 0, bool isMotorolaBy public override long Length { get; } -#if !NETSTANDARD2_1 +#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER private readonly byte[] _buffer = new byte[2048]; #endif @@ -59,7 +59,7 @@ public override void GetBytes(int index, Span bytes) while (totalBytesRead != bytes.Length) { var target = bytes.Slice(totalBytesRead); -#if NETSTANDARD2_1 +#if NETSTANDARD2_1 || NET8_0_OR_GREATER var bytesRead = _stream.Read(target); #else var len = Math.Min(bytes.Length - totalBytesRead, _buffer.Length); @@ -75,7 +75,6 @@ public override void GetBytes(int index, Span bytes) Debug.Assert(totalBytesRead <= bytes.Length); } - } private void Seek(int index) diff --git a/MetadataExtractor/IO/SequentialStreamReader.cs b/MetadataExtractor/IO/SequentialStreamReader.cs index 9dc5f995e..4fdd1af8e 100644 --- a/MetadataExtractor/IO/SequentialStreamReader.cs +++ b/MetadataExtractor/IO/SequentialStreamReader.cs @@ -51,7 +51,7 @@ public override void GetBytes(byte[] buffer, int offset, int count) } } -#if !NETSTANDARD2_1 +#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER private readonly byte[] _buffer = new byte[2048]; #endif @@ -62,7 +62,7 @@ public override void GetBytes(Span bytes) while (totalBytesRead != bytes.Length) { var target = bytes.Slice(totalBytesRead); -#if NETSTANDARD2_1 +#if NETSTANDARD2_1 || NET8_0_OR_GREATER var bytesRead = _stream.Read(target); #else var len = Math.Min(bytes.Length - totalBytesRead, _buffer.Length);