commit
fd51c1c984
1 changed files with 8 additions and 8 deletions
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
import asyncdispatch, os
|
import asyncdispatch, os
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
import winlean
|
import winlean
|
||||||
else:
|
else:
|
||||||
import posix
|
import posix
|
||||||
|
|
@ -34,7 +34,7 @@ type
|
||||||
fd: TAsyncFd
|
fd: TAsyncFd
|
||||||
offset: int64
|
offset: int64
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
proc getDesiredAccess(mode: FileMode): int32 =
|
proc getDesiredAccess(mode: FileMode): int32 =
|
||||||
case mode
|
case mode
|
||||||
of fmRead:
|
of fmRead:
|
||||||
|
|
@ -70,7 +70,7 @@ else:
|
||||||
|
|
||||||
proc getFileSize(f: AsyncFile): int64 =
|
proc getFileSize(f: AsyncFile): int64 =
|
||||||
## Retrieves the specified file's size.
|
## Retrieves the specified file's size.
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
var high: DWord
|
var high: DWord
|
||||||
let low = getFileSize(f.fd.THandle, addr high)
|
let low = getFileSize(f.fd.THandle, addr high)
|
||||||
if low == INVALID_FILE_SIZE:
|
if low == INVALID_FILE_SIZE:
|
||||||
|
|
@ -81,7 +81,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
||||||
## Opens a file specified by the path in ``filename`` using
|
## Opens a file specified by the path in ``filename`` using
|
||||||
## the specified ``mode`` asynchronously.
|
## the specified ``mode`` asynchronously.
|
||||||
new result
|
new result
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
let flags = FILE_FLAG_OVERLAPPED or FILE_ATTRIBUTE_NORMAL
|
let flags = FILE_FLAG_OVERLAPPED or FILE_ATTRIBUTE_NORMAL
|
||||||
let desiredAccess = getDesiredAccess(mode)
|
let desiredAccess = getDesiredAccess(mode)
|
||||||
let creationDisposition = getCreationDisposition(mode, filename)
|
let creationDisposition = getCreationDisposition(mode, filename)
|
||||||
|
|
@ -120,7 +120,7 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||||
## returned.
|
## returned.
|
||||||
var retFuture = newFuture[string]("asyncfile.read")
|
var retFuture = newFuture[string]("asyncfile.read")
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
var buffer = alloc0(size)
|
var buffer = alloc0(size)
|
||||||
|
|
||||||
var ol = PCustomOverlapped()
|
var ol = PCustomOverlapped()
|
||||||
|
|
@ -224,7 +224,7 @@ proc setFilePos*(f: AsyncFile, pos: int64) =
|
||||||
## Sets the position of the file pointer that is used for read/write
|
## Sets the position of the file pointer that is used for read/write
|
||||||
## operations. The file's first byte has the index zero.
|
## operations. The file's first byte has the index zero.
|
||||||
f.offset = pos
|
f.offset = pos
|
||||||
when not defined(windows):
|
when not defined(windows) and not defined(nimdoc):
|
||||||
let ret = lseek(f.fd.cint, pos, SEEK_SET)
|
let ret = lseek(f.fd.cint, pos, SEEK_SET)
|
||||||
if ret == -1:
|
if ret == -1:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
@ -245,7 +245,7 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
||||||
## specified file.
|
## specified file.
|
||||||
var retFuture = newFuture[void]("asyncfile.write")
|
var retFuture = newFuture[void]("asyncfile.write")
|
||||||
var copy = data
|
var copy = data
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
var buffer = alloc0(data.len)
|
var buffer = alloc0(data.len)
|
||||||
copyMem(buffer, addr copy[0], data.len)
|
copyMem(buffer, addr copy[0], data.len)
|
||||||
|
|
||||||
|
|
@ -316,7 +316,7 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
||||||
|
|
||||||
proc close*(f: AsyncFile) =
|
proc close*(f: AsyncFile) =
|
||||||
## Closes the file specified.
|
## Closes the file specified.
|
||||||
when defined(windows):
|
when defined(windows) or defined(nimdoc):
|
||||||
if not closeHandle(f.fd.THandle).bool:
|
if not closeHandle(f.fd.THandle).bool:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue