Skip to content

Commit

Permalink
Merge pull request #1406 from SeasideSt/fix-streaming-uploads-setting
Browse files Browse the repository at this point in the history
Fix streaming uploads
  • Loading branch information
jbrichau authored Mar 19, 2024
2 parents 33d0e82 + df0dc34 commit 63fbd49
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ I am an implementation of a ring buffer, i.e. a buffer where the start index can

I buffer a fixed amount of data and provide array like access to it.

Users use me mostly like an array. My only interesting method is #moveStartTo:, which moves the start index of the
buffer to the specified position. Example:
Users use me mostly like an array. My only interesting method is #moveStartTo:, which moves the start index of the buffer to the specified position. Example:

buffer
at: 1 put: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ do: aBlock
1
to: self size
do: [ :index |
aBlock value: (self at: index) ]
aBlock value: (self at: index) ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
operations
nextPutAllOn: aStream

self do: [ :element | aStream nextPut: element ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "mml 07/26/2019 15:33",
"commentStamp" : "JohanBrichau 3/19/2024 07:31",
"super" : "Object",
"category" : "Seaside-Zinc-Core",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*Seaside-Zinc-Core
streamUploads: aBoolean
^ self
optionAt: #streamUploads
put: aBoolean

| result |
result := self optionAt: #streamUploads put: aBoolean.
self delegate adaptor configureServerForBinaryReading.
^ result
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,27 @@ parseMultiPartFieldWithoutLengthWithBoundary: aBoundary writeOn: writer
ifTrue: [ "Found a boundary. We're done" true ]
ifFalse: [
| candidateIndex |
candidateIndex := boundaryCandidateIndex = 1
ifTrue: [ 2 ]
ifFalse: [ boundaryCandidateIndex ].
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) ].
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"
"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."
"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.
buffer nextPutAllOn: writer.
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"
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 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ partsDecodeWith: aDecoderBlock decodeFilesWith: aFileDecoderBlock
part contentType notNil and: [
part contentType isBinary ] ])
ifFalse: [
((part contentDispositionValues includes: 'form-data') and: [
part contentLength isNil ])
((part contentDispositionValues includes: 'form-data') and: [ part contentLength isNil ])
ifTrue: [
self
parseMultiPartFieldWithoutLengthWithMimePart: part
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
tests
testNextPutAllOn

| buffer temporaryFile |
buffer := GRPlatform current ringBufferClass on: (ByteArray new: 4).
buffer
at: 1 put: 128;
at: 2 put: 129;
at: 3 put: 130;
at: 4 put: 131.
temporaryFile := GRPlatform current newTemporaryFile.
[
GRPlatform current
writeFileStreamOn: temporaryFile
do: [ :strm | buffer nextPutAllOn: strm ]
binary: true.
self assert: (GRPlatform current contentsOfFile: temporaryFile binary: true) equals: #[128 129 130 131]
] ensure: [ GRPlatform current deleteFile: temporaryFile ].

buffer moveStartTo: 3.
temporaryFile := GRPlatform current newTemporaryFile.
[
GRPlatform current
writeFileStreamOn: temporaryFile
do: [ :strm | buffer nextPutAllOn: strm ]
binary: true.
self assert: (GRPlatform current contentsOfFile: temporaryFile binary: true) equals: #[130 131 128 129]
] ensure: [ GRPlatform current deleteFile: temporaryFile ].

0 comments on commit 63fbd49

Please sign in to comment.