Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parameter EOLCharacterLength and detect it automatically #46

Merged
merged 2 commits into from
Apr 12, 2023

Conversation

jkrzefski
Copy link
Contributor

Take a look at this line:

$partLength = $currentOffset - $partOffset - strlen($trimmed) - (2 * $eofLength);

I was wondering, why $eofLength had to be multiplied with 2. Then I realized, this was to necessary to remove the length of the delimiter plus the EOL after the delimiter plus the EOL in the previous line.

I realized, this could be an issue. When the EOL character length varies between the previous and the current line, this approach would fail. So I changed it to remove the length of $line instead of $trimmed, so the current EOL is already subtracted. Then I only have to subtract one $eofLength. But it must be the EOL character length of the previous line. So now, at the end of each iteration, I keep track of the EOL character length.

This entirely obsoletes the constructor parameter $EOLCharacterLength, because now it is fully dynamic. So, I removed this parameter. I no not see this as a breaking change as using excess parameters in object initialization does not fail and raises no warning.

I changed the tests accordingly, so they pass again. But to prove my point, I split my pull-request in two commits. The first commit removed the parameter for $EOLCharacterLength from the test-case testNoNewLineAtTheEndOfThePartsWhenNewLineIsOneCharacterLong. This makes the test fail. The second commit changes the implementation of StreamedPart and now the test passes again.

@rcambien rcambien merged commit 68e5499 into Riverline:master Apr 12, 2023
@jkrzefski jkrzefski deleted the patch-1 branch April 20, 2023 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants