From f723335f9ece25f0ec46df6b984257143a1fc669 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 14 Nov 2020 18:38:10 +0100 Subject: [PATCH] doc: remove documentation for stream._construct() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The feature was added in Node.js v15.0.0. Fixes: https://github.com/nodejs/node/issues/36058 PR-URL: https://github.com/nodejs/node/pull/36119 Reviewed-By: Antoine du Hamel Reviewed-By: Michaƫl Zasso Reviewed-By: Richard Lau Reviewed-By: Beth Griggs --- doc/api/stream.md | 107 ---------------------------------------------- 1 file changed, 107 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index eed68fcc54ea31..10c68d9b4dd074 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1953,56 +1953,6 @@ const myWritable = new Writable({ }); ``` -#### `writable._construct(callback)` - - -* `callback` {Function} Call this function (optionally with an error - argument) when the stream has finished initializing. - -The `_construct()` method MUST NOT be called directly. It may be implemented -by child classes, and if so, will be called by the internal `Writable` -class methods only. - -This optional function will be called in a tick after the stream constructor -has returned, delaying any `_write()`, `_final()` and `_destroy()` calls until -`callback` is called. This is useful to initialize state or asynchronously -initialize resources before the stream can be used. - -```js -const { Writable } = require('stream'); -const fs = require('fs'); - -class WriteStream extends Writable { - constructor(filename) { - super(); - this.filename = filename; - this.fd = fd; - } - _construct(callback) { - fs.open(this.filename, (fd, err) => { - if (err) { - callback(err); - } else { - this.fd = fd; - callback(); - } - }); - } - _write(chunk, encoding, callback) { - fs.write(this.fd, chunk, callback); - } - _destroy(err, callback) { - if (this.fd) { - fs.close(this.fd, (er) => callback(er || err)); - } else { - callback(err); - } - } -} -``` - #### `writable._write(chunk, encoding, callback)` - -* `callback` {Function} Call this function (optionally with an error - argument) when the stream has finished initializing. - -The `_construct()` method MUST NOT be called directly. It may be implemented -by child classes, and if so, will be called by the internal `Readable` -class methods only. - -This optional function will be scheduled in the next tick by the stream -constructor, delaying any `_read()` and `_destroy()` calls until `callback` is -called. This is useful to initialize state or asynchronously initialize -resources before the stream can be used. - -```js -const { Readable } = require('stream'); -const fs = require('fs'); - -class ReadStream extends Readable { - constructor(filename) { - super(); - this.filename = filename; - this.fd = null; - } - _construct(callback) { - fs.open(this.filename, (fd, err) => { - if (err) { - callback(err); - } else { - this.fd = fd; - callback(); - } - }); - } - _read(n) { - const buf = Buffer.alloc(n); - fs.read(this.fd, buf, 0, n, null, (err, bytesRead) => { - if (err) { - this.destroy(err); - } else { - this.push(bytesRead > 0 ? buf.slice(0, bytesRead) : null); - } - }); - } - _destroy(err, callback) { - if (this.fd) { - fs.close(this.fd, (er) => callback(er || err)); - } else { - callback(err); - } - } -} -``` - #### `readable._read(size)`