Prepare for Nim v1.0.2

This commit is contained in:
Zahary Karadjov 2019-10-02 13:54:13 +03:00 committed by zah
parent 0c3ab3eb78
commit 11b6a831cb
2 changed files with 18 additions and 13 deletions

View File

@ -1,13 +1,14 @@
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)
when not compiles(writeFile("filename", @[byte(1)])):
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)

View File

@ -6,7 +6,11 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import unittest,
../stew/byteutils
../stew/[byteutils, io]
proc compilationTest {.exportc: "compilationTest".} =
var bytes = @[1.byte, 2, 3, 4]
writeFile("test", bytes)
suite "Byte utils":
let simpleBArray = [0x12.byte, 0x34, 0x56, 0x78]