mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Merge pull request #4083 from vegansk/vm_readfile
Add ``readFile`` implementation for nimvm
This commit is contained in:
@@ -2628,6 +2628,14 @@ when not defined(JS): #and not defined(nimscript):
|
||||
else: result = 0
|
||||
|
||||
when defined(nimscript):
|
||||
proc readFile*(filename: string): string {.tags: [ReadIOEffect], benign.}
|
||||
## Opens a file named `filename` for reading.
|
||||
##
|
||||
## Then calls `readAll <#readAll>`_ and closes the file afterwards.
|
||||
## Returns the string. Raises an IO exception in case of an error. If
|
||||
## you need to call this inside a compile time macro you can use
|
||||
## `staticRead <#staticRead>`_.
|
||||
|
||||
proc writeFile*(filename, content: string) {.tags: [WriteIOEffect], benign.}
|
||||
## Opens a file named `filename` for writing. Then writes the
|
||||
## `content` completely to the file and closes the file afterwards.
|
||||
|
||||
Reference in New Issue
Block a user