Merge pull request #1221 from rbehrends/readallbuf-fix
Fixed readAllBuffer() to avoid adding garbage bytes at end.
This commit is contained in:
commit
6ae46265cc
1 changed files with 8 additions and 4 deletions
|
|
@ -115,10 +115,14 @@ proc readAllBuffer(file: TFile): string =
|
||||||
# bytes we need to read before the buffer is empty.
|
# bytes we need to read before the buffer is empty.
|
||||||
result = ""
|
result = ""
|
||||||
var buffer = newString(BufSize)
|
var buffer = newString(BufSize)
|
||||||
var bytesRead = BufSize
|
while true:
|
||||||
while bytesRead == BufSize:
|
var bytesRead = readBuffer(file, addr(buffer[0]), BufSize)
|
||||||
bytesRead = readBuffer(file, addr(buffer[0]), BufSize)
|
if bytesRead == BufSize:
|
||||||
result.add(buffer)
|
result.add(buffer)
|
||||||
|
else:
|
||||||
|
buffer.setLen(bytesRead)
|
||||||
|
result.add(buffer)
|
||||||
|
break
|
||||||
|
|
||||||
proc rawFileSize(file: TFile): int =
|
proc rawFileSize(file: TFile): int =
|
||||||
# this does not raise an error opposed to `getFileSize`
|
# this does not raise an error opposed to `getFileSize`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue