Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,7 @@ private static string ToChunkedBase64String(IPackagePart part)
}

private static string ToChunkedBase64String(byte[] byteArray)
{
// The MIME specification defines a maximum line length of 76 characters
// for a Base64-encoded string. Therefore, we need to break down the
// Base64 string into chunks of up to 76 characters each.
const int maxLineLength = 76;

return Convert.ToBase64String(byteArray)
.Select((@char, index) => new { Character = @char, Chunk = index / maxLineLength })
.GroupBy(charAndChunk => charAndChunk.Chunk)
.Aggregate(
new StringBuilder(),
(sb, grouping) => sb
.Append(grouping.Aggregate(
new StringBuilder(),
(chunkSb, charAndChunk) => chunkSb.Append(charAndChunk.Character),
chunkSb => chunkSb.ToString()))
.Append(Environment.NewLine),
sb => sb.ToString());
}
=> Convert.ToBase64String(byteArray, Base64FormattingOptions.InsertLineBreaks);

internal static IPackageFactory<TPackage> WithFlatOpcTemplate<TPackage>(this IPackageFactory<TPackage> builder, string text, bool? isEditable = default)
where TPackage : OpenXmlPackage
Expand Down
Loading