getFileSize and setFileSize procedures for File and AsyncFile

Platform independent procedure to set a file length. Useful when
replacing file content.
This commit is contained in:
Emery Hemingway 2017-04-04 20:26:59 -05:00
commit bc5c2d8414
No known key found for this signature in database
GPG key ID: E7AB426C639DCB96
4 changed files with 34 additions and 5 deletions

View file

@ -11,9 +11,10 @@ proc main() {.async.} =
# Simple write/read test.
block:
var file = openAsync(fn, fmReadWrite)
await file.write("test")
await file.write("testing")
file.setFilePos(0)
await file.write("foo")
file.setFileSize(4)
file.setFilePos(0)
let data = await file.readAll()
doAssert data == "foot"
@ -24,7 +25,7 @@ proc main() {.async.} =
var file = openAsync(fn, fmAppend)
await file.write("\ntest2")
let errorTest = file.readAll()
echo await errorTest
yield errorTest
doAssert errorTest.failed
file.close()
file = openAsync(fn, fmRead)