Don't raise OSError from memFileInput()

This commit is contained in:
Zahary Karadjov 2020-08-02 20:16:47 +03:00
commit 87309f3120
No known key found for this signature in database
GPG key ID: C8936F8A3073D609

View file

@ -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