mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-02 15:23:49 +00:00
Add writeFile(string, openarray[byte])
This commit is contained in:
parent
58a313d8eb
commit
7fa381eb8d
13
std_shims/io.nim
Normal file
13
std_shims/io.nim
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
proc writeFile*(filename: string, content: openarray[byte]) =
|
||||||
|
## Opens a file named `filename` for writing. Then writes the
|
||||||
|
## `content` completely to the file and closes the file afterwards.
|
||||||
|
## Raises an IO exception in case of an error.
|
||||||
|
var f: File
|
||||||
|
if open(f, filename, fmWrite):
|
||||||
|
try:
|
||||||
|
f.writeBuffer(unsafeAddr content[0], content.len)
|
||||||
|
finally:
|
||||||
|
close(f)
|
||||||
|
else:
|
||||||
|
raise newException(IOError, "cannot open: " & filename)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user