Illegal storage access, is equivalent to nil pointer dereference in Nim, it is
not an exception.
Checking the code of writeData:
proc writeData*(s, unused: Stream, buffer: pointer,
bufLen: int) {.deprecated.} =
## low level proc that writes an untyped `buffer` of `bufLen` size
## to the stream `s`.
s.writeDataImpl(s, buffer, bufLen)
Run
This means that buffer is a nil pointer.
Checking the code of newFileStream:
proc newFileStream*(filename: string, mode: FileMode = fmRead, bufSize: int
= -1): FileStream =
## creates a new stream from the file named `filename` with the mode
`mode`.
## If the file cannot be opened, nil is returned. See the `system
## <system.html>`_ module for a list of available FileMode enums.
var f: File
if open(f, filename, mode, bufSize): result = newFileStream(f)
Run
\--> Your file couldn't be opened so you have a nil pointer.
This is mentionned in the [documentation of
Streams](https://nim-lang.org/docs/streams.html#newFileStream,File). There is a
very new proc called openFileStream that will properly raise an IOError, use it.
Alternatively test for nil:
if dest.isNil:
raise newException(IOError, "Couldn't open destination file")
Run