diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2014-03-29 12:23:21 +0100 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2014-03-29 12:24:54 +0100 |
commit | d41988d8b25ffd42c8b1dd4b4626a2933db500de (patch) | |
tree | b7130eb3791ddbe0115ef0446c959153ba9c558e /lib/wrappers/zip | |
parent | cc718435b3455783fba97e1494dea15d603b81fd (diff) | |
download | Nim-d41988d8b25ffd42c8b1dd4b4626a2933db500de.tar.gz |
Modifies inflate() to return a discardable bool. Refs #1048.
Diffstat (limited to 'lib/wrappers/zip')
-rw-r--r-- | lib/wrappers/zip/zlib.nim | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/wrappers/zip/zlib.nim b/lib/wrappers/zip/zlib.nim index a755305e6..f09b8b97a 100644 --- a/lib/wrappers/zip/zlib.nim +++ b/lib/wrappers/zip/zlib.nim @@ -293,26 +293,17 @@ proc uncompress*(sourceBuf: cstring, sourceLen: int): string = result = decompressed -proc inflate*(buffer: var string) = +proc inflate*(buffer: var string): bool {.discardable.} = ## Convenience proc which inflates a string containing compressed data. ## ## Passing a nil string will crash this proc in release mode and assert in ## debug mode. It is ok to pass a buffer which doesn't contain deflated data, - ## in this case the proc won't modify the buffer. To check if data was - ## inflated compare the final length of the `buffer` with its original value. - ## Example: + ## in this case the proc won't modify the buffer. ## - ## .. code-block:: nimrod - ## var data: string - ## # Put something into data. - ## let originalLen = len(data) - ## data.inflate() - ## if originalLen != len(data): - ## echo "Data was inflated!" - ## else: - ## echo "Nothing to inflate" + ## Returns true if `buffer` was successfully inflated. assert (not buffer.isNil) if buffer.len < 1: return let temp = uncompress(addr(buffer[0]), buffer.len) if not temp.isNil: buffer = temp + result = true |