Added overload for fileInput
- Make it symetrical to `fileOutput`
This commit is contained in:
parent
e56e9c71e1
commit
eb2ad0c441
1 changed files with 25 additions and 9 deletions
|
|
@ -399,6 +399,30 @@ let fileInputVTable = InputStreamVTable(
|
||||||
raise newException(IOError, "Failed to close file", err)
|
raise newException(IOError, "Failed to close file", err)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
proc fileInput*(file: File,
|
||||||
|
offset = 0,
|
||||||
|
pageSize = defaultPageSize): InputStreamHandle
|
||||||
|
{.raises: [IOError, OSError].} =
|
||||||
|
## Creates an input stream for reading the contents of a file
|
||||||
|
## through Nim's `io` module.
|
||||||
|
##
|
||||||
|
## Parameters:
|
||||||
|
##
|
||||||
|
## ``file``
|
||||||
|
## The file to read.
|
||||||
|
##
|
||||||
|
## ``offset``
|
||||||
|
## Initial position in the file where reading should start.
|
||||||
|
##
|
||||||
|
|
||||||
|
if offset != 0:
|
||||||
|
setFilePos(file, offset)
|
||||||
|
|
||||||
|
makeHandle FileInputStream(
|
||||||
|
vtable: vtableAddr fileInputVTable,
|
||||||
|
buffers: initPageBuffers(pageSize),
|
||||||
|
file: file)
|
||||||
|
|
||||||
proc fileInput*(filename: string,
|
proc fileInput*(filename: string,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
pageSize = defaultPageSize): InputStreamHandle
|
pageSize = defaultPageSize): InputStreamHandle
|
||||||
|
|
@ -415,14 +439,7 @@ proc fileInput*(filename: string,
|
||||||
## Initial position in the file where reading should start.
|
## Initial position in the file where reading should start.
|
||||||
##
|
##
|
||||||
let file = system.open(filename, fmRead)
|
let file = system.open(filename, fmRead)
|
||||||
|
return fileInput(file, offset, pageSize)
|
||||||
if offset != 0:
|
|
||||||
setFilePos(file, offset)
|
|
||||||
|
|
||||||
makeHandle FileInputStream(
|
|
||||||
vtable: vtableAddr fileInputVTable,
|
|
||||||
buffers: initPageBuffers(pageSize),
|
|
||||||
file: file)
|
|
||||||
|
|
||||||
proc unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle =
|
proc unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle =
|
||||||
let head = unsafeAddr mem[0]
|
let head = unsafeAddr mem[0]
|
||||||
|
|
@ -948,4 +965,3 @@ proc pos*(s: InputStream): int {.inline.} =
|
||||||
when fsAsyncSupport:
|
when fsAsyncSupport:
|
||||||
template pos*(s: AsyncInputStream): int =
|
template pos*(s: AsyncInputStream): int =
|
||||||
pos InputStream(s)
|
pos InputStream(s)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue