Skip to content

Commit cfff266

Browse files
committed
crypto.decompress offset parameter
1 parent 0188046 commit cfff266

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

docs/Runtime Environment/Crypto.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,23 @@ print(crypto.verify(msg, "rsa-sha256", pub, sig)) --> true
506506
### `crypto.decompress`
507507
Decompresses a DEFLATE-compressed string (one might call this an "INFLATE" function). Compatible with gzip and zlib headers and footers.
508508
#### Parameters
509-
1. The string to decompress.
509+
1. `data` — The string to decompress.
510+
2. `offset` — Optional starting position inside `data`, using `string.sub` semantics. Defaults to the beginning of `data`. To provide an `offset` without a decompressed size, pass `nil` as the third argument.
511+
3. `decompressed_size` — Optional size of the decompressed output. When only two arguments are given, the second argument is treated as `decompressed_size`.
510512
#### Returns
511513
1. The decompressed string.
512514
2. A table with extra information: `compressed_size`, `checksum_present`, `checksum_mismatch`
513515
```pluto
514-
local decompressed, info = require"crypto".decompress("\xF3\x48\xCD\xC9\xC9\xD7\x51\x08\xC8\x29\x2D\xC9\x57\x04")
516+
local deflated = "\xF3\x48\xCD\xC9\xC9\xD7\x51\x08\xC8\x29\x2D\xC9\x57\x04"
517+
518+
local decompressed, info = require"crypto".decompress(deflated)
515519
print(decompressed) --> Hello, Pluto!
516520
print(info.compressed_size) --> 14
517521
print(info.checksum_present) --> false
518522
print(info.checksum_mismatch) --> false
523+
524+
-- Decompress from an offset
525+
decompressed, info = require"crypto".decompress("Don't mind me" .. deflated, 14, nil)
526+
print(decompressed) --> Hello, Pluto
527+
print(info.compressed_size) --> 14
519528
```

0 commit comments

Comments
 (0)