parent
5ea80b43b1
commit
19164929ed
3 changed files with 16 additions and 0 deletions
|
|
@ -78,7 +78,10 @@ proc getFileSize*(f: AsyncFile): int64 =
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
result = (high shl 32) or low
|
result = (high shl 32) or low
|
||||||
else:
|
else:
|
||||||
|
let curPos = lseek(f.fd.cint, 0, SEEK_CUR)
|
||||||
result = lseek(f.fd.cint, 0, SEEK_END)
|
result = lseek(f.fd.cint, 0, SEEK_END)
|
||||||
|
f.offset = lseek(f.fd.cint, curPos, SEEK_SET)
|
||||||
|
assert(f.offset == curPos)
|
||||||
|
|
||||||
proc newAsyncFile*(fd: AsyncFd): AsyncFile =
|
proc newAsyncFile*(fd: AsyncFd): AsyncFile =
|
||||||
## Creates `AsyncFile` with a previously opened file descriptor `fd`.
|
## Creates `AsyncFile` with a previously opened file descriptor `fd`.
|
||||||
|
|
@ -281,6 +284,7 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||||
result = false # We still want this callback to be called.
|
result = false # We still want this callback to be called.
|
||||||
elif res == 0:
|
elif res == 0:
|
||||||
# EOF
|
# EOF
|
||||||
|
f.offset = lseek(fd.cint, 0, SEEK_CUR)
|
||||||
retFuture.complete("")
|
retFuture.complete("")
|
||||||
else:
|
else:
|
||||||
readBuffer.setLen(res)
|
readBuffer.setLen(res)
|
||||||
|
|
|
||||||
1
tests/async/hello.txt
Normal file
1
tests/async/hello.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello humans!
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
discard """
|
discard """
|
||||||
|
output: '''13
|
||||||
|
hello humans!
|
||||||
|
13
|
||||||
|
'''
|
||||||
file: "tasyncfile.nim"
|
file: "tasyncfile.nim"
|
||||||
exitcode: 0
|
exitcode: 0
|
||||||
"""
|
"""
|
||||||
|
|
@ -48,5 +52,12 @@ proc main() {.async.} =
|
||||||
doAssert data == "t3"
|
doAssert data == "t3"
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
# Issue #7347
|
||||||
|
block:
|
||||||
|
let appDir = getAppDir()
|
||||||
|
var file = openAsync(appDir & DirSep & "hello.txt")
|
||||||
|
echo file.getFileSize()
|
||||||
|
echo await file.readAll()
|
||||||
|
echo file.getFilePos()
|
||||||
|
|
||||||
waitFor main()
|
waitFor main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue