diff --git a/repository/Zinc-HTTP.package/ZnByteArrayEntity.class/instance/readFrom..st b/repository/Zinc-HTTP.package/ZnByteArrayEntity.class/instance/readFrom..st index 0e2ffabe..8abf2b65 100644 --- a/repository/Zinc-HTTP.package/ZnByteArrayEntity.class/instance/readFrom..st +++ b/repository/Zinc-HTTP.package/ZnByteArrayEntity.class/instance/readFrom..st @@ -1,18 +1,16 @@ initialize-release readFrom: stream - self contentLength ifNil: [ self bytes: (ZnUtils readUpToEnd: stream limit: (ZnCurrentOptions at: #maximumEntitySize)). - self contentLength: self bytes size - ] - ifNotNil: [ | byteArray | - + self contentLength: self bytes size ] + ifNotNil: [ | byteArray readCount | self contentLength > (ZnCurrentOptions at: #maximumEntitySize) ifTrue: [ ZnEntityTooLarge signal ]. byteArray := ByteArray ofSize: self contentLength. - self contentLength > ZnUtils streamingBufferSize + readCount := self contentLength > ZnUtils streamingBufferSize ifTrue: [ ZnUtils streamFrom: stream to: byteArray writeStream size: self contentLength ] - ifFalse: [ stream next: self contentLength into: byteArray ]. - self bytes: byteArray - ] \ No newline at end of file + ifFalse: [ stream readInto: byteArray startingAt: 1 count: self contentLength ]. + readCount = self contentLength + ifTrue: [ self bytes: byteArray ] + ifFalse: [ self bytes: (byteArray copyFrom: 1 to: readCount); contentLength: readCount ] ] \ No newline at end of file diff --git a/repository/Zinc-HTTP.package/ZnStringEntity.class/instance/readFrom..st b/repository/Zinc-HTTP.package/ZnStringEntity.class/instance/readFrom..st index 4bc40252..40bc2d7c 100644 --- a/repository/Zinc-HTTP.package/ZnStringEntity.class/instance/readFrom..st +++ b/repository/Zinc-HTTP.package/ZnStringEntity.class/instance/readFrom..st @@ -5,7 +5,7 @@ readFrom: stream readStream := total ifNotNil: [ ZnLimitedReadStream on: stream limit: total ] ifNil: [ stream ]. buffer := String new: (ZnUtils streamingBufferSize min: (total ifNil: [ ZnUtils streamingBufferSize ])). stringStream := nil. - totalRead := 0. + totalRead := read := 0. self initializeEncoder. [ readStream atEnd ] whileFalse: [ [ read := encoder readInto: buffer startingAt: 1 count: buffer size fromStream: readStream ] @@ -22,7 +22,7 @@ readFrom: stream ifTrue: [ ZnEntityTooLarge signal ]. stringStream ifNil: [ readStream atEnd - ifTrue: [ ^ self string: (buffer copyFrom: 1 to: read) ] + ifTrue: [ ^ self string: (buffer copyFrom: 1 to: read); computeContentLength ] ifFalse: [ stringStream := (total ifNil: [ buffer species new ] ifNotNil: [ buffer species new: total ]) writeStream ] ]. stringStream next: read putAll: buffer startingAt: 1. ZnUtils signalProgress: totalRead total: total ]. diff --git a/repository/Zinc-HTTP.package/ZnUtils.class/class/streamFrom.to.size..st b/repository/Zinc-HTTP.package/ZnUtils.class/class/streamFrom.to.size..st index 81433730..66cdfef7 100644 --- a/repository/Zinc-HTTP.package/ZnUtils.class/class/streamFrom.to.size..st +++ b/repository/Zinc-HTTP.package/ZnUtils.class/class/streamFrom.to.size..st @@ -4,13 +4,14 @@ streamFrom: inputStream to: outputStream size: totalSize bufferSize := self streamingBufferSize min: totalSize. buffer := (inputStream isBinary ifTrue: [ ByteArray ] ifFalse: [ String ]) new: bufferSize. leftToRead := totalSize. - [ leftToRead > 0 ] - whileTrue: [ | readCount | - readCount := bufferSize min: leftToRead. - inputStream next: readCount into: buffer. + [ leftToRead > 0 and: [ inputStream atEnd not ] ] + whileTrue: [ | toReadCount readCount | + toReadCount := bufferSize min: leftToRead. + readCount := inputStream readInto: buffer startingAt: 1 count: toReadCount. leftToRead := leftToRead - readCount. outputStream next: readCount putAll: buffer startingAt: 1. leftToRead > 0 ifTrue: [ self signalProgress: (totalSize - leftToRead) total: totalSize. - outputStream flush ] ] \ No newline at end of file + outputStream flush ] ]. + ^ totalSize - leftToRead \ No newline at end of file