-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code style and comment fixes, as suggested by @theseion
- Loading branch information
Showing
6 changed files
with
48 additions
and
64 deletions.
There are no files selected for viewing
95 changes: 40 additions & 55 deletions
95
...artFormDataEntity.class/instance/parseMultiPartFieldWithoutLengthWithBoundary.writeOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,53 @@ | ||
private | ||
parseMultiPartFieldWithoutLengthWithBoundary: aBoundary writeOn: writer | ||
|
||
| bufferSize rawBuffer buffer boundaryMarker | | ||
"Can't simply use a larger buffer as we don't want to read past a boundary, | ||
those bytes will belong to the next part" | ||
"Can't simply use a larger buffer as we don't want to read past a boundary, those bytes will belong to the next part" | ||
bufferSize := aBoundary size. | ||
rawBuffer := ByteArray new: bufferSize. | ||
buffer := GRPlatform current ringBufferClass on: rawBuffer. | ||
boundaryMarker := aBoundary first. | ||
|
||
stream atEnd ifFalse: [ | ||
"#next:into: answers a copy of the buffer if not enough bytes could be read" | ||
"Use rawBuffer here so we can use the primitive to replace the bytes in the | ||
buffer directly" | ||
stream | ||
next: bufferSize | ||
into: rawBuffer ]. | ||
"#next:into: answers a copy of the buffer if not enough bytes could be read. | ||
Use rawBuffer here so we can use the primitive to replace the bytes in the buffer directly" | ||
stream next: bufferSize into: rawBuffer ]. | ||
|
||
[ (buffer | ||
indexOf: boundaryMarker | ||
ifAbsent: [ nil ]) | ||
ifNotNil: [ :boundaryCandidateIndex | | ||
(boundaryCandidateIndex = 1 and: [ | ||
buffer = aBoundary ]) | ||
ifTrue: [ | ||
"Found a boundary. We're done" | ||
true ] | ||
ifFalse: [ | ||
| candidateIndex | | ||
candidateIndex := boundaryCandidateIndex = 1 | ||
ifTrue: [ 2 ] | ||
ifFalse: [ boundaryCandidateIndex ]. | ||
"Write all the bytes that we know are not part of a boundary" | ||
1 | ||
to: candidateIndex - 1 | ||
do: [ :index | writer nextPut: (buffer at: index) ]. | ||
"Move the rest of the buffer to the beginning of the buffer" | ||
buffer moveStartTo: candidateIndex. | ||
|
||
"Fill the rest of the buffer" | ||
"Use rawBuffer here so we can use the primitive to replace the bytes in the | ||
buffer directly" | ||
rawBuffer := buffer | ||
copyFrom: 1 | ||
to: bufferSize. | ||
stream | ||
next: candidateIndex - 1 | ||
into: rawBuffer | ||
startingAt: bufferSize - candidateIndex + 2. | ||
buffer initializeWithCollection: rawBuffer. | ||
"If the candidate was really the first token of the boundary | ||
[ | ||
(buffer indexOf: boundaryMarker ifAbsent: [ nil ]) | ||
ifNotNil: [ :boundaryCandidateIndex | | ||
(boundaryCandidateIndex = 1 and: [ buffer = aBoundary ]) | ||
ifTrue: [ "Found a boundary. We're done" true ] | ||
ifFalse: [ | ||
| candidateIndex | | ||
candidateIndex := boundaryCandidateIndex = 1 | ||
ifTrue: [ 2 ] | ||
ifFalse: [ boundaryCandidateIndex ]. | ||
"Write all the bytes that we know are not part of a boundary" | ||
1 to: candidateIndex - 1 do: [ :index | | ||
writer nextPut: (buffer at: index) ]. | ||
"Move the rest of the buffer to the beginning of the buffer" | ||
buffer moveStartTo: candidateIndex. | ||
"Fill the rest of the buffer. | ||
Use rawBuffer here so we can use the primitive to replace the bytes in the | ||
buffer directly" | ||
rawBuffer := buffer copyFrom: 1 to: bufferSize. | ||
stream | ||
next: candidateIndex - 1 | ||
into: rawBuffer | ||
startingAt: bufferSize - candidateIndex + 2. | ||
buffer initializeWithCollection: rawBuffer. | ||
"If the candidate was really the first token of the boundary | ||
then we now have loaded the full boundary into the buffer. | ||
If not we have to check for the next boundary candidate as | ||
we might have loaded the next boundary partially." | ||
buffer = aBoundary ] ] | ||
ifNil: [ | ||
writer nextPutAll: buffer. | ||
stream atEnd | ||
ifFalse: [ | ||
"#next:into: answers a copy of the buffer if not enough bytes could be read" | ||
"Use rawBuffer here so we can use the primitive to replace the bytes in the | ||
buffer = aBoundary ] ] | ||
ifNil: [ | ||
writer nextPutAll: buffer. | ||
stream atEnd | ||
ifFalse: [ "#next:into: answers a copy of the buffer if not enough bytes could be read""Use rawBuffer here so we can use the primitive to replace the bytes in the | ||
buffer directly" | ||
stream | ||
next: bufferSize | ||
into: rawBuffer. | ||
buffer moveStartTo: 1. | ||
false ] | ||
ifTrue: [ true ] ] ] whileFalse | ||
stream next: bufferSize into: rawBuffer. | ||
buffer moveStartTo: 1. | ||
false ] | ||
ifTrue: [ true ] ] ] whileFalse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureDelegate.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
initialize-release | ||
initialization | ||
configureDelegate | ||
"Set the main delegate of my server to the default one." | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...e-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureServerForBinaryReading.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/server..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/serverClass..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters