diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/std/sha1.nim | 2 | ||||
-rw-r--r-- | lib/system/io.nim | 12 | ||||
-rw-r--r-- | lib/wrappers/openssl.nim | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/std/sha1.nim b/lib/std/sha1.nim index 958ac8ab0..b74b285f8 100644 --- a/lib/std/sha1.nim +++ b/lib/std/sha1.nim @@ -231,7 +231,7 @@ proc secureHashFile*(filename: string): SecureHash = var state = newSha1State() var buffer = newString(BufferLength) while true: - let length = readChars(f, buffer, 0, BufferLength) + let length = readChars(f, buffer) if length == 0: break buffer.setLen(length) diff --git a/lib/system/io.nim b/lib/system/io.nim index 016db4bac..460be516e 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -174,14 +174,18 @@ proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int ## `len` (if not as many bytes are remaining), but not greater. result = readBuffer(f, addr(a[start]), len) +proc readChars*(f: File, a: var openArray[char]): int {.tags: [ReadIOEffect], benign.} = + ## reads up to `a.len` bytes into the buffer `a`. Returns + ## the actual number of bytes that have been read which may be less than + ## `a.len` (if not as many bytes are remaining), but not greater. + result = readBuffer(f, addr(a[0]), a.len) + proc readChars*(f: File, a: var openArray[char], start, len: Natural): int {. - tags: [ReadIOEffect], benign.} = + tags: [ReadIOEffect], benign, deprecated: + "use other `readChars` overload, possibly via: readChars(toOpenArray(buf, start, len-1))".} = ## reads `len` bytes into the buffer `a` starting at ``a[start]``. Returns ## the actual number of bytes that have been read which may be less than ## `len` (if not as many bytes are remaining), but not greater. - ## - ## **Warning:** The buffer `a` must be pre-allocated. This can be done - ## using, for example, ``newString``. if (start + len) > len(a): raiseEIO("buffer overflow: (start+len) > length of openarray buffer") result = readBuffer(f, addr(a[start]), len) diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index b3ab0cfc0..3c9c92b0d 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -760,7 +760,7 @@ proc md5_File*(file: string): string {.raises: [IOError,Exception].} = ctx: MD5_CTX discard md5_Init(ctx) - while(let bytes = f.readChars(buf, 0, sz); bytes > 0): + while (let bytes = f.readChars(buf); bytes > 0): discard md5_Update(ctx, buf[0].addr, cast[csize_t](bytes)) discard md5_Final(buf[0].addr, ctx) |