Don't raise OSError from memFileInput()
This commit is contained in:
parent
5df69fc696
commit
87309f3120
1 changed files with 20 additions and 17 deletions
|
|
@ -166,7 +166,7 @@ let memFileInputVTable = InputStreamVTable(
|
||||||
)
|
)
|
||||||
|
|
||||||
proc memFileInput*(filename: string, mappedSize = -1, offset = 0): InputStreamHandle
|
proc memFileInput*(filename: string, mappedSize = -1, offset = 0): InputStreamHandle
|
||||||
{.raises: [IOError, OSError].} =
|
{.raises: [IOError].} =
|
||||||
## Creates an input stream for reading the contents of a memory-mapped file.
|
## Creates an input stream for reading the contents of a memory-mapped file.
|
||||||
##
|
##
|
||||||
## Using this API will provide better performance than `fileInput`,
|
## Using this API will provide better performance than `fileInput`,
|
||||||
|
|
@ -187,6 +187,7 @@ proc memFileInput*(filename: string, mappedSize = -1, offset = 0): InputStreamHa
|
||||||
# Nim's memfiles module will fail to map an empty file,
|
# Nim's memfiles module will fail to map an empty file,
|
||||||
# but we don't consider this a problem. The stream will
|
# but we don't consider this a problem. The stream will
|
||||||
# be in non-readable state from the start.
|
# be in non-readable state from the start.
|
||||||
|
try:
|
||||||
let fileSize = getFileSize(filename)
|
let fileSize = getFileSize(filename)
|
||||||
if fileSize == 0:
|
if fileSize == 0:
|
||||||
return makeHandle InputStream()
|
return makeHandle InputStream()
|
||||||
|
|
@ -205,6 +206,8 @@ proc memFileInput*(filename: string, mappedSize = -1, offset = 0): InputStreamHa
|
||||||
startAddr: head,
|
startAddr: head,
|
||||||
endAddr: offset(head, mappedSize)),
|
endAddr: offset(head, mappedSize)),
|
||||||
file: memFile)
|
file: memFile)
|
||||||
|
except OSError as err:
|
||||||
|
raise newException(IOError, err.msg, err)
|
||||||
|
|
||||||
func getNewSpan(s: InputStream) =
|
func getNewSpan(s: InputStream) =
|
||||||
let buffers = s.buffers
|
let buffers = s.buffers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue