@@ -139,12 +139,18 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
139139
140140 protected void ReadHeader ( Stream stream )
141141 {
142- // TODO: Check length and throw if the header cannot be read.
143- _ = Read ( stream , out this . fileHeader , IconDir . Size ) ;
142+ Span < byte > buffer = stackalloc byte [ IconDirEntry . Size ] ;
143+
144+ // ICONDIR
145+ _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDir . Size ] ) , IconDir . Size ) ;
146+ this . fileHeader = IconDir . Parse ( buffer ) ;
147+
148+ // ICONDIRENTRY
144149 this . Entries = new IconDirEntry [ this . FileHeader . Count ] ;
145150 for ( int i = 0 ; i < this . Entries . Length ; i ++ )
146151 {
147- _ = Read ( stream , out this . Entries [ i ] , IconDirEntry . Size ) ;
152+ _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDirEntry . Size ] ) , IconDirEntry . Size ) ;
153+ this . Entries [ i ] = IconDirEntry . Parse ( buffer ) ;
148154 }
149155
150156 int width = 0 ;
@@ -175,18 +181,6 @@ protected void ReadHeader(Stream stream)
175181 this . Dimensions = new ( width , height ) ;
176182 }
177183
178- private static int Read < T > ( Stream stream , out T data , int size )
179- where T : unmanaged
180- {
181- // TODO: Use explicit parsing methods for each T type.
182- // See PngHeader.Parse() for example.
183- Span < byte > buffer = stackalloc byte [ size ] ;
184-
185- _ = IconAssert . EndOfStream ( stream . Read ( buffer ) , size ) ;
186- data = MemoryMarshal . Cast < byte , T > ( buffer ) [ 0 ] ;
187- return size ;
188- }
189-
190184 private IImageDecoderInternals GetDecoder ( bool isPng )
191185 {
192186 if ( isPng )
0 commit comments