dotnet / dotnet/Open-XML-SDK

FlatOpc: line break at the end of binary part format

Open
#1,237 3 comments 0 reactions 1 assignee Claimed by @hunyu View on GitHub
enhancement
Dominant language
C#
Stars
4.6k
Forks
605
PR merge metrics
No merged PRs in 30d

Description

Hi, I have a question about the next method:
https://github.com/OfficeDev/Open-XML-SDK/blob/main/src/DocumentFormat.OpenXml/Packaging/OpenXmlPackage.FlatOpc.cs#L140-L159

According to the [old blog post](https://learn.microsoft.com/en-us/archive/blogs/ericwhite/the-flat-opc-format) from Eric White:
> the string must be broken into lines of 76 characters, and there **must not be a line break at the beginning or end of the data**

But the linked code adds a line break at the end of the data.

Also, the logic of this method is not obvious from my point of view.
If it is a bug then it might be simplified a bit:
```cs
const int maxLineLength = 76;

var str = Convert.ToBase64String(byteArray);

var sb = new StringBuilder();
for (var i = 0; i < str.Length; i += maxLineLength)
{
if (i > 0)
{
sb.AppendLine();
}

sb.Append(str.Substring(i, System.Math.Min(maxLineLength, str.Length - i)));
}

return sb.ToString();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.