mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-05 09:24:36 +00:00
Improved reading and writing large Office files without copying them into memory (#1243)
This commit is contained in:
1 parent
918572c158
commit
dbe609a9a7
37 files changed
+1161
-471
No files matched your search
@@ -63,7 +63,7 @@ public sealed class HtmlSegmentFormatTests
|
||||
[Test]
|
||||
public async Task TheWordsGoToTheModelAndTheMarkupBecomesTags()
|
||||
{
|
||||
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())
|
||||
{
|
||||
@@ -192,7 +192,7 @@ public sealed class HtmlSegmentFormatTests
|
||||
var page =$"<p>Intro text.</p>{Nested("div", 300, "Deep block")}<p>Before {Nested("span", 300, "deep words")} after.</p><p>Outro text.</p>";
|
||||
File.WriteAllText(this.source, page, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
||||
|
||||
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);
|
||||
var written = await File.ReadAllTextAsync(this.target);
|
||||
|
||||
@@ -209,7 +209,7 @@ public sealed class HtmlSegmentFormatTests
|
||||
// Thousands of elements without their end tags, as a broken generator may write them:
|
||||
File.WriteAllText(this.source, "<p>" + string.Concat(Enumerable.Repeat("<span>", 20_000)) + "Words</p>", new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
||||
|
||||
Assert.That(async () => await this.format.ReadAsync(this.source, CancellationToken.None), Throws.Exception);
|
||||
Assert.That(async () => await this.format.ReadAsync(this.source, NullLogger.Instance, CancellationToken.None), Throws.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -218,7 +218,7 @@ public sealed class HtmlSegmentFormatTests
|
||||
// A card, as many pages show them: a link around a heading and a paragraph:
|
||||
File.WriteAllText(this.source, "<a href=\"/mars\"><div><h3>Mars</h3><p>The red planet.</p></div></a>", new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
||||
|
||||
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();
|
||||
|
||||
Assert.That(keys, Is.EqualTo(new[] { "Mars", "The red planet." }));
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public sealed class HtmlSegmentFormatTests
|
||||
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user