Improved reading and writing large Office files without copying them into memory (#1243)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-28 23:03:30 +01:00
1 parent 918572c158
commit dbe609a9a7
37 files changed
+1161 -471

No files matched your search

@@ -383,7 +383,7 @@ public sealed class WordInlineFormattingTests
private void CreateSentence() => Create(this.source, Paragraph(Run("This is "), Bold("very"), Run(" "), Italic("important"), Run(" and "), Link("linked"), Run(" text.")));
private async Task<List<string>> KeysAsync() => (await this.format.ReadAsync(this.source, CancellationToken.None)).Select(segment => segment.Key).ToList();
private async Task<List<string>> KeysAsync() => (await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None)).Select(segment => segment.Key).ToList();
private Task<SegmentWriteResult> WriteAsync(string key, string newText)
{
@@ -44,7 +44,7 @@ public sealed class WordSegmentFormatTests
[Test]
public async Task TheParagraphsBecomeSegmentsWithTags()
{
var keys = (await this.format.ReadAsync(this.source, CancellationToken.None)).Select(segment => segment.Key).ToList();
var keys = (await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None)).Select(segment => segment.Key).ToList();
using (Assert.EnterMultipleScope())
{
@@ -201,7 +201,7 @@ public sealed class WordSegmentFormatTests
using (var sourceToExtend = WordprocessingDocument.Open(this.source, true))
BodyOf(sourceToExtend).AppendChild(bound);
var keys = (await this.format.ReadAsync(this.source, CancellationToken.None)).Select(segment => segment.Key).ToList();
var keys = (await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None)).Select(segment => segment.Key).ToList();
await this.format.WriteAsync(this.source, this.target, await this.ResultsAsync(key => key.ToUpperInvariant()), string.Empty, NullLogger.Instance, CancellationToken.None);
using var sourceDocument = WordprocessingDocument.Open(this.source, false);
@@ -224,7 +224,7 @@ public sealed class WordSegmentFormatTests
new W.DeletedRun(new W.Run(new W.DeletedText("gone"))) { Id = "1", Author = "Tester" },
new W.InsertedRun(Run("new")) { Id = "2", Author = "Tester" }));
var keys = (await this.format.ReadAsync(this.source, CancellationToken.None)).Select(segment => segment.Key).ToList();
var keys = (await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None)).Select(segment => segment.Key).ToList();
await this.format.WriteAsync(this.source, this.target, await this.ResultsAsync(key => key.ToUpperInvariant()), string.Empty, NullLogger.Instance, CancellationToken.None);
using var sourceDocument = WordprocessingDocument.Open(this.source, false);
@@ -250,7 +250,7 @@ public sealed class WordSegmentFormatTests
Run("Introduction")),
Paragraph(Run("Methods"), new W.Run(new W.FieldChar { FieldCharType = W.FieldCharValues.End })));
var keys = (await this.format.ReadAsync(this.source, CancellationToken.None)).Select(segment => segment.Key).ToList();
var keys = (await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None)).Select(segment => segment.Key).ToList();
await this.format.WriteAsync(this.source, this.target, await this.ResultsAsync(key => key.ToUpperInvariant()), string.Empty, NullLogger.Instance, CancellationToken.None);
using var sourceDocument = WordprocessingDocument.Open(this.source, false);
@@ -324,7 +324,7 @@ public sealed class WordSegmentFormatTests
private async Task<SegmentResults> ResultsAsync(Func<string, string> transform)
{
var segments = await this.format.ReadAsync(this.source, CancellationToken.None);
var segments = await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None);
return new SegmentResults(segments
.Where(segment => segment.HasWords)
.DistinctBy(segment => segment.Key)