diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-04-20 11:23:41 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-04-28 07:56:14 +0300 |
commit | 3d65a3b13e61f136dc09027aa12473c2b3003725 (patch) | |
tree | 012259a22a22fec5325afd386bbae62e3293a09f /doc/api/zlib.md | |
parent | 46c880b99b4a74c3a7c99fdd824bf9ce22333987 (diff) |
doc: add `node:` prefix for all core modules
Some core modules can be loaded with or without the `node:` prefix.
Using the prefix disambiguates which specifiers refer to core modules.
This commit updates the docs to use the prefix everywhere a core module
is referenced.
PR-URL: https://github.com/nodejs/node/pull/42752
Fixes: https://github.com/nodejs/node/issues/38343
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Diffstat (limited to 'doc/api/zlib.md')
-rw-r--r-- | doc/api/zlib.md | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 0b1a7cc7ca4..ee54973e5d3 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -6,13 +6,13 @@ <!-- source_link=lib/zlib.js --> -The `zlib` module provides compression functionality implemented using Gzip, -Deflate/Inflate, and Brotli. +The `node:zlib` module provides compression functionality implemented using +Gzip, Deflate/Inflate, and Brotli. To access it: ```js -const zlib = require('zlib'); +const zlib = require('node:zlib'); ``` Compression and decompression are built around the Node.js [Streams API][]. @@ -22,12 +22,12 @@ piping the source stream through a `zlib` `Transform` stream into a destination stream: ```js -const { createGzip } = require('zlib'); -const { pipeline } = require('stream'); +const { createGzip } = require('node:zlib'); +const { pipeline } = require('node:stream'); const { createReadStream, createWriteStream -} = require('fs'); +} = require('node:fs'); const gzip = createGzip(); const source = createReadStream('input.txt'); @@ -42,7 +42,7 @@ pipeline(source, gzip, destination, (err) => { // Or, Promisified -const { promisify } = require('util'); +const { promisify } = require('node:util'); const pipe = promisify(pipeline); async function do_gzip(input, output) { @@ -62,7 +62,7 @@ do_gzip('input.txt', 'input.txt.gz') It is also possible to compress or decompress data in a single step: ```js -const { deflate, unzip } = require('zlib'); +const { deflate, unzip } = require('node:zlib'); const input = '.................................'; deflate(input, (err, buffer) => { @@ -84,7 +84,7 @@ unzip(buffer, (err, buffer) => { // Or, Promisified -const { promisify } = require('util'); +const { promisify } = require('node:util'); const do_unzip = promisify(unzip); do_unzip(buffer) @@ -105,7 +105,7 @@ Creating and using a large number of zlib objects simultaneously can cause significant memory fragmentation. ```js -const zlib = require('zlib'); +const zlib = require('node:zlib'); const payload = Buffer.from('This is some data'); @@ -124,7 +124,7 @@ operations be cached to avoid duplication of effort. ## Compressing HTTP requests and responses -The `zlib` module can be used to implement support for the `gzip`, `deflate` +The `node:zlib` module can be used to implement support for the `gzip`, `deflate` and `br` content-encoding mechanisms defined by [HTTP](https://tools.ietf.org/html/rfc7230#section-4.2). @@ -140,10 +140,10 @@ tradeoffs involved in `zlib` usage. ```js // Client request example -const zlib = require('zlib'); -const http = require('http'); -const fs = require('fs'); -const { pipeline } = require('stream'); +const zlib = require('node:zlib'); +const http = require('node:http'); +const fs = require('node:fs'); +const { pipeline } = require('node:stream'); const request = http.get({ host: 'example.com', path: '/', @@ -181,10 +181,10 @@ request.on('response', (response) => { // server example // Running a gzip operation on every request is quite expensive. // It would be much more efficient to cache the compressed buffer. -const zlib = require('zlib'); -const http = require('http'); -const fs = require('fs'); -const { pipeline } = require('stream'); +const zlib = require('node:zlib'); +const http = require('node:http'); +const fs = require('node:fs'); +const { pipeline } = require('node:stream'); http.createServer((request, response) => { const raw = fs.createReadStream('index.html'); @@ -319,9 +319,9 @@ In the following example, `flush()` is used to write a compressed partial HTTP response to the client: ```js -const zlib = require('zlib'); -const http = require('http'); -const { pipeline } = require('stream'); +const zlib = require('node:zlib'); +const http = require('node:http'); +const { pipeline } = require('node:stream'); http.createServer((request, response) => { // For the sake of simplicity, the Accept-Encoding checks are omitted. @@ -365,14 +365,14 @@ added: v0.5.8 ### zlib constants All of the constants defined in `zlib.h` are also defined on -`require('zlib').constants`. In the normal course of operations, it will not be -necessary to use these constants. They are documented so that their presence is -not surprising. This section is taken almost directly from the +`require('node:zlib').constants`. In the normal course of operations, it will +not be necessary to use these constants. They are documented so that their +presence is not surprising. This section is taken almost directly from the [zlib documentation][]. -Previously, the constants were available directly from `require('zlib')`, for -instance `zlib.Z_NO_FLUSH`. Accessing the constants directly from the module is -currently still possible but is deprecated. +Previously, the constants were available directly from `require('node:zlib')`, +for instance `zlib.Z_NO_FLUSH`. Accessing the constants directly from the module +is currently still possible but is deprecated. Allowed flush values. @@ -678,11 +678,11 @@ changes: description: This class was renamed from `Zlib` to `ZlibBase`. --> -Not exported by the `zlib` module. It is documented here because it is the base -class of the compressor/decompressor classes. +Not exported by the `node:zlib` module. It is documented here because it is the +base class of the compressor/decompressor classes. -This class inherits from [`stream.Transform`][], allowing `zlib` objects to be -used in pipes and similar stream operations. +This class inherits from [`stream.Transform`][], allowing `node:zlib` objects to +be used in pipes and similar stream operations. ### `zlib.bytesRead` |