File tree Expand file tree Collapse file tree 7 files changed +21
-4
lines changed Expand file tree Collapse file tree 7 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,8 @@ private static IEnumerable<Directory> ProcessChunk(PngChunk chunk)
170
170
try
171
171
{
172
172
using var inflaterStream = new DeflateStream ( new MemoryStream ( compressedProfile ) , CompressionMode . Decompress ) ;
173
- iccDirectory = new IccReader ( ) . Extract ( new IndexedCapturingReader ( inflaterStream ) ) ;
173
+ using var iccReader = new IndexedCapturingReader ( inflaterStream ) ;
174
+ iccDirectory = new IccReader ( ) . Extract ( iccReader ) ;
174
175
iccDirectory . Parent = directory ;
175
176
}
176
177
catch ( Exception e )
Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ public static IReadOnlyList<Directory> ReadMetadata(Stream stream)
41
41
var directories = new List < Directory > ( ) ;
42
42
43
43
var handler = new ExifTiffHandler ( directories , exifStartOffset : 0 ) ;
44
- TiffReader . ProcessTiff ( new IndexedCapturingReader ( stream ) , handler ) ;
44
+
45
+ using var reader = new IndexedCapturingReader ( stream ) ;
46
+ TiffReader . ProcessTiff ( reader , handler ) ;
45
47
46
48
return directories ;
47
49
}
Original file line number Diff line number Diff line change 1
1
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
2
2
3
+ using System . Buffers ;
4
+
3
5
namespace MetadataExtractor . IO
4
6
{
5
7
/// <author>Drew Noakes https://drewnoakes.com</author>
6
- public sealed class IndexedCapturingReader : IndexedReader
8
+ public sealed class IndexedCapturingReader : IndexedReader , IDisposable
7
9
{
8
10
private const int DefaultChunkLength = 2 * 1024 ;
9
11
@@ -99,7 +101,7 @@ private bool IsValidIndex(int index, int bytesRequested)
99
101
{
100
102
Debug . Assert ( ! _isStreamFinished ) ;
101
103
102
- var chunk = new byte [ _chunkLength ] ;
104
+ var chunk = ArrayPool < byte > . Shared . Rent ( _chunkLength ) ;
103
105
var totalBytesRead = 0 ;
104
106
while ( ! _isStreamFinished && totalBytesRead != _chunkLength )
105
107
{
@@ -129,6 +131,14 @@ private bool IsValidIndex(int index, int bytesRequested)
129
131
return true ;
130
132
}
131
133
134
+ public void Dispose ( )
135
+ {
136
+ foreach ( var chunk in _chunks )
137
+ {
138
+ ArrayPool < byte > . Shared . Return ( chunk ) ;
139
+ }
140
+ }
141
+
132
142
public override int ToUnshiftedOffset ( int localOffset ) => localOffset ;
133
143
134
144
private void GetPosition ( int index , out int chunkIndex , out int innerIndex )
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ MetadataExtractor.Formats.Png.PngDirectory.GetPngChunkType() -> MetadataExtracto
111
111
MetadataExtractor.Formats.Png.PngDirectory.PngDirectory(MetadataExtractor.Formats.Png.PngChunkType pngChunkType) -> void
112
112
MetadataExtractor.GeoLocation.Equals(MetadataExtractor.GeoLocation other) -> bool
113
113
MetadataExtractor.GeoLocation.GeoLocation() -> void
114
+ MetadataExtractor.IO.IndexedCapturingReader.Dispose() -> void
114
115
MetadataExtractor.IO.IndexedReader.GetByte(int index) -> byte
115
116
MetadataExtractor.IO.IndexedReader.GetBytes(int index, int count) -> byte[]!
116
117
MetadataExtractor.Util.FileType.Avif = 28 -> MetadataExtractor.Util.FileType
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ MetadataExtractor.Formats.Png.PngDirectory.GetPngChunkType() -> MetadataExtracto
110
110
MetadataExtractor.Formats.Png.PngDirectory.PngDirectory(MetadataExtractor.Formats.Png.PngChunkType pngChunkType) -> void
111
111
MetadataExtractor.GeoLocation.Equals(MetadataExtractor.GeoLocation other) -> bool
112
112
MetadataExtractor.GeoLocation.GeoLocation() -> void
113
+ MetadataExtractor.IO.IndexedCapturingReader.Dispose() -> void
113
114
MetadataExtractor.IO.IndexedReader.GetByte(int index) -> byte
114
115
MetadataExtractor.IO.IndexedReader.GetBytes(int index, int count) -> byte[]!
115
116
MetadataExtractor.Util.FileType.Avif = 28 -> MetadataExtractor.Util.FileType
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ MetadataExtractor.Formats.Png.PngDirectory.GetPngChunkType() -> MetadataExtracto
111
111
MetadataExtractor.Formats.Png.PngDirectory.PngDirectory(MetadataExtractor.Formats.Png.PngChunkType pngChunkType) -> void
112
112
MetadataExtractor.GeoLocation.Equals(MetadataExtractor.GeoLocation other) -> bool
113
113
MetadataExtractor.GeoLocation.GeoLocation() -> void
114
+ MetadataExtractor.IO.IndexedCapturingReader.Dispose() -> void
114
115
MetadataExtractor.IO.IndexedReader.GetByte(int index) -> byte
115
116
MetadataExtractor.IO.IndexedReader.GetBytes(int index, int count) -> byte[]!
116
117
MetadataExtractor.Util.FileType.Avif = 28 -> MetadataExtractor.Util.FileType
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ MetadataExtractor.Formats.Png.PngDirectory.GetPngChunkType() -> MetadataExtracto
110
110
MetadataExtractor.Formats.Png.PngDirectory.PngDirectory(MetadataExtractor.Formats.Png.PngChunkType pngChunkType) -> void
111
111
MetadataExtractor.GeoLocation.Equals(MetadataExtractor.GeoLocation other) -> bool
112
112
MetadataExtractor.GeoLocation.GeoLocation() -> void
113
+ MetadataExtractor.IO.IndexedCapturingReader.Dispose() -> void
113
114
MetadataExtractor.IO.IndexedReader.GetByte(int index) -> byte
114
115
MetadataExtractor.IO.IndexedReader.GetBytes(int index, int count) -> byte[]!
115
116
MetadataExtractor.Util.FileType.Avif = 28 -> MetadataExtractor.Util.FileType
You can’t perform that action at this time.
0 commit comments