Skip to content

Commit b948dce

Browse files
author
markzegarelli
authored
Update how zlib must be referenced in functions docs (#3438)
1 parent f08b3b2 commit b948dce

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/_includes/content/functions/runtime.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,30 @@ The following dependencies are installed in the function environment by default.
2828
- [`uuidv5 v1.0.0`](https://www.npmjs.com/package/uuidv5) exposed as `uuidv5`
2929
- [`xml v1.0.1`](https://www.npmjs.com/package/xml) exposed as `xml`
3030
- [`xml2js v0.4.23`](https://www.npmjs.com/package/xml2js) exposed as `xml2js`
31-
- [`zlib v1.0.5`](https://www.npmjs.com/package/zlib) exposed as `zlib`
31+
- [`zlib v1.0.5`](https://www.npmjs.com/package/zlib) exposed as `zlib.zlib`
32+
33+
`zlib`'s asynchronous methods `inflate` and `deflate` must be used with `async` or `await`. For example:
34+
35+
```js
36+
zlib = zlib.zlib; // Required to access zlib objects and associated functions
37+
async function onRequest(request, settings) {
38+
const body = request.json();
39+
40+
const input = 'something';
41+
42+
// Calling inflateSync method
43+
var deflated = zlib.deflateSync(input);
44+
45+
console.log(deflated.toString('base64'));
46+
47+
// Calling inflateSync method
48+
var inflated = zlib.inflateSync(new Buffer.from(deflated)).toString();
49+
50+
console.log(inflated);
51+
52+
console.log('Done');
53+
}
54+
```
3255

3356
Only the [`crypto` Node.js module](https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html ) is included (exposed as `crypto`). [Other built-in Node.js modules](https://nodejs.org/api/modules.html) are not available.
3457

0 commit comments

Comments
 (0)