mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-13 12:36:57 +00:00
Prepare for Nim v1.0.2
This commit is contained in:
parent
0c3ab3eb78
commit
11b6a831cb
25
stew/io.nim
25
stew/io.nim
@ -1,13 +1,14 @@
|
|||||||
proc writeFile*(filename: string, content: openarray[byte]) =
|
when not compiles(writeFile("filename", @[byte(1)])):
|
||||||
## Opens a file named `filename` for writing. Then writes the
|
proc writeFile*(filename: string, content: openarray[byte]) =
|
||||||
## `content` completely to the file and closes the file afterwards.
|
## Opens a file named `filename` for writing. Then writes the
|
||||||
## Raises an IO exception in case of an error.
|
## `content` completely to the file and closes the file afterwards.
|
||||||
var f: File
|
## Raises an IO exception in case of an error.
|
||||||
if open(f, filename, fmWrite):
|
var f: File
|
||||||
try:
|
if open(f, filename, fmWrite):
|
||||||
f.writeBuffer(unsafeAddr content[0], content.len)
|
try:
|
||||||
finally:
|
f.writeBuffer(unsafeAddr content[0], content.len)
|
||||||
close(f)
|
finally:
|
||||||
else:
|
close(f)
|
||||||
raise newException(IOError, "cannot open: " & filename)
|
else:
|
||||||
|
raise newException(IOError, "cannot open: " & filename)
|
||||||
|
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import unittest,
|
import unittest,
|
||||||
../stew/byteutils
|
../stew/[byteutils, io]
|
||||||
|
|
||||||
|
proc compilationTest {.exportc: "compilationTest".} =
|
||||||
|
var bytes = @[1.byte, 2, 3, 4]
|
||||||
|
writeFile("test", bytes)
|
||||||
|
|
||||||
suite "Byte utils":
|
suite "Byte utils":
|
||||||
let simpleBArray = [0x12.byte, 0x34, 0x56, 0x78]
|
let simpleBArray = [0x12.byte, 0x34, 0x56, 0x78]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user