NanoXLSX.Reader 3.2.1
Loading...
Searching...
No Matches
ReaderPlugInHandler.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using System.Diagnostics.CodeAnalysis;
9using System.IO;
10using NanoXLSX.Interfaces;
11using NanoXLSX.Interfaces.Reader;
12using NanoXLSX.Registry;
13
15{
19 internal static class ReaderPlugInHandler
20 {
29 [ExcludeFromCodeCoverage] // No testable logic, only plug-in handling
30 internal static void HandleInlineQueuePlugins(Stream stream, Workbook workbook, string queueUuid, IOptions readerOptions, int? index)
31 {
32 if (stream == null)
33 {
34 return;
35 }
36 // Inline plug-ins reset Position to 0 to re-read the part. If the caller passed a
37 // non-seekable stream (e.g. a deflate stream from a ZIP entry), the contract can only
38 // be honored by buffering once. Skip the buffer when no inline plug-ins exist.
39 Stream working = stream;
40 MemoryStream owned = null;
41 if (!stream.CanSeek && PlugInLoader.HasQueuePlugins(queueUuid))
42 {
43 owned = new MemoryStream();
44 stream.CopyTo(owned);
45 owned.Position = 0;
46 working = owned;
47 }
48 try
49 {
50 IPluginInlineReader queueReader = null;
51 string lastUuid = null;
52 do
53 {
54 string currentUuid;
55 queueReader = PlugInLoader.GetNextQueuePlugIn<IPluginInlineReader>(queueUuid, lastUuid, out currentUuid);
56 if (queueReader != null)
57 {
58 if (working.CanSeek)
59 {
60 working.Position = 0;
61 }
62 queueReader.Init(working, workbook, readerOptions, index);
63 queueReader.Execute();
64 lastUuid = currentUuid;
65 }
66 else
67 {
68 lastUuid = null;
69 }
70
71 } while (queueReader != null);
72 }
73 finally
74 {
75 owned?.Dispose();
76 }
77 }
78
86 [ExcludeFromCodeCoverage] // No testable logic, only plug-in handling
87 internal static void HandleInlineQueueProcessorPlugins(Workbook workbook, string queueUuid, IOptions readerOptions, int? index)
88 {
89 IPluginInlineReadProcessor queueProcessor = null;
90 string lastUuid = null;
91 do
92 {
93 string currentUuid;
94 queueProcessor = PlugInLoader.GetNextQueuePlugIn<IPluginInlineReadProcessor>(queueUuid, lastUuid, out currentUuid);
95 if (queueProcessor != null)
96 {
97 queueProcessor.Init(workbook, readerOptions, index);
98 queueProcessor.Execute();
99 lastUuid = currentUuid;
100 }
101 else
102 {
103 lastUuid = null;
104 }
105
106 } while (queueProcessor != null);
107 }
108 }
109}