Skip to content

Commit

Permalink
Change ZnRingBuffer>>writeAllOn: to an implementation that works for …
Browse files Browse the repository at this point in the history
…a -ring- (duh) and rename it to nextPutAllOn:
  • Loading branch information
jbrichau committed Mar 19, 2024
1 parent 27c8905 commit 38c4668
Show file tree
Hide file tree
Showing 7 changed files with 35 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
@@ -0,0 +1,4 @@
private
nextPutAllOn: aStream

self do: [ :element | aStream nextPut: element ]

This file was deleted.

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
Expand Up @@ -36,7 +36,7 @@ parseMultiPartFieldWithoutLengthWithBoundary: aBoundary writeOn: writer
If not we have to check for the next boundary candidate as we might have loaded the next boundary partially."
buffer = aBoundary ] ]
ifNil: [
buffer writeAllOn: writer.
buffer nextPutAllOn: writer.
stream atEnd
ifFalse: [
"#next:into: answers a copy of the buffer if not enough bytes could be read.
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 ].

This file was deleted.

0 comments on commit 38c4668

Please sign in to comment.