forked from nim-lang/langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipes.nim
27 lines (20 loc) · 757 Bytes
/
pipes.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import faststreams/asynctools_adapters, streams, os
when defined(windows):
import winlean
proc writeToPipe*(p: AsyncPipe, data: pointer, nbytes: int) =
if writeFile(p.getWriteHandle, data, int32(nbytes), nil, nil) == 0:
raiseOsError(osLastError())
else:
import posix
proc writeToPipe*(p: AsyncPipe, data: pointer, nbytes: int) =
if posix.write(p.getWriteHandle, data, cint(nbytes)) < 0:
raiseOsError(osLastError())
proc copyFileToPipe*(param: tuple[pipe: AsyncPipe, file: File]) {.thread.} =
var
inputStream = newFileStream(param.file)
ch = "^"
ch[0] = inputStream.readChar()
while ch[0] != '\0':
writeToPipe(param.pipe, ch[0].addr, 1)
ch[0] = inputStream.readChar();
closeWrite(param.pipe, false)