From cbfd20860657d542a815fcfbba546fe178af9a80 Mon Sep 17 00:00:00 2001 From: Johan Brichau Date: Sun, 24 Dec 2023 10:50:40 +0100 Subject: [PATCH] Code style and comment fixes, as suggested by @theseion --- ...FieldWithoutLengthWithBoundary.writeOn..st | 95 ++++++++----------- .../partsDecodeWith.decodeFilesWith..st | 9 +- .../instance/configureDelegate.st | 2 +- .../configureServerForBinaryReading.st | 2 +- .../instance/server..st | 2 +- .../instance/serverClass..st | 2 +- 6 files changed, 48 insertions(+), 64 deletions(-) diff --git a/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/parseMultiPartFieldWithoutLengthWithBoundary.writeOn..st b/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/parseMultiPartFieldWithoutLengthWithBoundary.writeOn..st index 3164f9eae..775ee58e4 100644 --- a/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/parseMultiPartFieldWithoutLengthWithBoundary.writeOn..st +++ b/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/parseMultiPartFieldWithoutLengthWithBoundary.writeOn..st @@ -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 \ No newline at end of file + stream next: bufferSize into: rawBuffer. + buffer moveStartTo: 1. + false ] + ifTrue: [ true ] ] ] whileFalse \ No newline at end of file diff --git a/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/partsDecodeWith.decodeFilesWith..st b/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/partsDecodeWith.decodeFilesWith..st index 04d6d35f2..bec19f0fd 100644 --- a/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/partsDecodeWith.decodeFilesWith..st +++ b/repository/Seaside-Zinc-Core.package/ZnStreamingMultiPartFormDataEntity.class/instance/partsDecodeWith.decodeFilesWith..st @@ -13,12 +13,11 @@ partsDecodeWith: aDecoderBlock decodeFilesWith: aFileDecoderBlock part := ZnMimePart new headers: (ZnHeaders readFrom: stream); yourself. - "When a value is empty (see comment in #parseMultiPartFieldWithoutLengthWithBoundary:writeOn:) - and it is the last part then parsing headers will consumed the rest of the end boundary and the - stream will be at the end. In this case, the part will not have any headers" + "When a part is empty and it is the last part then parsing headers will have consumed + the rest of the end boundary and the stream will be at the end. + In this case, the part will not have any headers." (part hasHeaders not or: [ - "The final boundary may be read as a header when - the last part was not a file part" + "The final boundary may have been read as a header when the last part was not a file part" part headers includesKey: endBoundary ]) ifFalse: [ (part fileName notNil or: [ part contentType notNil and: [ diff --git a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureDelegate.st b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureDelegate.st index fb9098cdf..3fb88ec68 100644 --- a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureDelegate.st +++ b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureDelegate.st @@ -1,4 +1,4 @@ -initialize-release +initialization configureDelegate "Set the main delegate of my server to the default one." diff --git a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureServerForBinaryReading.st b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureServerForBinaryReading.st index b73b5799e..6df7b2c5f 100644 --- a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureServerForBinaryReading.st +++ b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/configureServerForBinaryReading.st @@ -1,4 +1,4 @@ -initialize-release +initialization configureServerForBinaryReading "Seaside wants to do its own text conversions" diff --git a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/server..st b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/server..st index 19155e190..872b4e01f 100644 --- a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/server..st +++ b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/server..st @@ -1,4 +1,4 @@ -initialize-release +initialization server: znServer "I initialize the actual ZnServer instance that I will be using to znServer, to prevent a fallback to #defaultZnServer" diff --git a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/serverClass..st b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/serverClass..st index 50d5d09dd..b2e8f7581 100644 --- a/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/serverClass..st +++ b/repository/Seaside-Zinc-Core.package/ZnZincServerAdaptor.class/instance/serverClass..st @@ -1,4 +1,4 @@ -initialize-release +initialization serverClass: znServerClass "I initialize the actual ZnServer instance that I will be using, by instanciating znServerClass using my port"