Browse Source

doc: fix code examples in zlib.md

* Use test() instead of match() in boolean context.
* Add spaces in code example.
* Fix typo.

PR-URL: https://github.com/nodejs/node/pull/13342
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
v6
Vse Mozhet Byt 8 years ago
parent
commit
6cfdbc74d9
  1. 8
      doc/api/zlib.md

8
doc/api/zlib.md

@ -102,10 +102,10 @@ http.createServer((request, response) => {
// Note: This is not a conformant accept-encoding parser. // Note: This is not a conformant accept-encoding parser.
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3 // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
if (acceptEncoding.match(/\bdeflate\b/)) { if (/\bdeflate\b/.test(acceptEncoding)) {
response.writeHead(200, { 'Content-Encoding': 'deflate' }); response.writeHead(200, { 'Content-Encoding': 'deflate' });
raw.pipe(zlib.createDeflate()).pipe(response); raw.pipe(zlib.createDeflate()).pipe(response);
} else if (acceptEncoding.match(/\bgzip\b/)) { } else if (/\bgzip\b/.test(acceptEncoding)) {
response.writeHead(200, { 'Content-Encoding': 'gzip' }); response.writeHead(200, { 'Content-Encoding': 'gzip' });
raw.pipe(zlib.createGzip()).pipe(response); raw.pipe(zlib.createGzip()).pipe(response);
} else { } else {
@ -119,7 +119,7 @@ By default, the `zlib` methods will throw an error when decompressing
truncated data. However, if it is known that the data is incomplete, or truncated data. However, if it is known that the data is incomplete, or
the desire is to inspect only the beginning of a compressed file, it is the desire is to inspect only the beginning of a compressed file, it is
possible to suppress the default error handling by changing the flushing possible to suppress the default error handling by changing the flushing
method that is used to compressed the last chunk of input data: method that is used to decompress the last chunk of input data:
```js ```js
// This is a truncated version of the buffer from the above examples // This is a truncated version of the buffer from the above examples
@ -127,7 +127,7 @@ const buffer = Buffer.from('eJzT0yMA', 'base64');
zlib.unzip( zlib.unzip(
buffer, buffer,
{finishFlush: zlib.constants.Z_SYNC_FLUSH}, { finishFlush: zlib.constants.Z_SYNC_FLUSH },
(err, buffer) => { (err, buffer) => {
if (!err) { if (!err) {
console.log(buffer.toString()); console.log(buffer.toString());

Loading…
Cancel
Save