mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
Merge pull request #1221 from rbehrends/readallbuf-fix
Fixed readAllBuffer() to avoid adding garbage bytes at end.
This commit is contained in:
@@ -115,10 +115,14 @@ proc readAllBuffer(file: TFile): string =
|
||||
# bytes we need to read before the buffer is empty.
|
||||
result = ""
|
||||
var buffer = newString(BufSize)
|
||||
var bytesRead = BufSize
|
||||
while bytesRead == BufSize:
|
||||
bytesRead = readBuffer(file, addr(buffer[0]), BufSize)
|
||||
result.add(buffer)
|
||||
while true:
|
||||
var bytesRead = readBuffer(file, addr(buffer[0]), BufSize)
|
||||
if bytesRead == BufSize:
|
||||
result.add(buffer)
|
||||
else:
|
||||
buffer.setLen(bytesRead)
|
||||
result.add(buffer)
|
||||
break
|
||||
|
||||
proc rawFileSize(file: TFile): int =
|
||||
# this does not raise an error opposed to `getFileSize`
|
||||
|
||||
Reference in New Issue
Block a user