mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
system.writeFile has been overloaded to also support openarray[byte] (#12313)
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
## Library additions
|
||||
|
||||
- `macros.newLit` now works for ref object types.
|
||||
|
||||
- `system.writeFile` has been overloaded to also support `openarray[byte]`.
|
||||
|
||||
## Library changes
|
||||
|
||||
|
||||
@@ -679,6 +679,18 @@ proc writeFile*(filename, content: string) {.tags: [WriteIOEffect], benign.} =
|
||||
else:
|
||||
sysFatal(IOError, "cannot open: " & filename)
|
||||
|
||||
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)
|
||||
|
||||
proc readLines*(filename: string, n = 1.Natural): seq[TaintedString] =
|
||||
## read `n` lines from the file named `filename`. Raises an IO exception
|
||||
|
||||
Reference in New Issue
Block a user