@@ -1953,56 +1953,6 @@ const myWritable = new Writable({
1953
1953
});
1954
1954
```
1955
1955
1956
- #### ` writable._construct(callback) `
1957
- <!-- YAML
1958
- added: v14.13.1
1959
- -->
1960
-
1961
- * ` callback ` {Function} Call this function (optionally with an error
1962
- argument) when the stream has finished initializing.
1963
-
1964
- The ` _construct() ` method MUST NOT be called directly. It may be implemented
1965
- by child classes, and if so, will be called by the internal ` Writable `
1966
- class methods only.
1967
-
1968
- This optional function will be called in a tick after the stream constructor
1969
- has returned, delaying any ` _write() ` , ` _final() ` and ` _destroy() ` calls until
1970
- ` callback ` is called. This is useful to initialize state or asynchronously
1971
- initialize resources before the stream can be used.
1972
-
1973
- ``` js
1974
- const { Writable } = require (' stream' );
1975
- const fs = require (' fs' );
1976
-
1977
- class WriteStream extends Writable {
1978
- constructor (filename ) {
1979
- super ();
1980
- this .filename = filename;
1981
- this .fd = fd;
1982
- }
1983
- _construct (callback ) {
1984
- fs .open (this .filename , (fd , err ) => {
1985
- if (err) {
1986
- callback (err);
1987
- } else {
1988
- this .fd = fd;
1989
- callback ();
1990
- }
1991
- });
1992
- }
1993
- _write (chunk , encoding , callback ) {
1994
- fs .write (this .fd , chunk, callback);
1995
- }
1996
- _destroy (err , callback ) {
1997
- if (this .fd ) {
1998
- fs .close (this .fd , (er ) => callback (er || err));
1999
- } else {
2000
- callback (err);
2001
- }
2002
- }
2003
- }
2004
- ```
2005
-
2006
1956
#### ` writable._write(chunk, encoding, callback) `
2007
1957
<!-- YAML
2008
1958
changes:
@@ -2269,63 +2219,6 @@ const myReadable = new Readable({
2269
2219
});
2270
2220
```
2271
2221
2272
- #### ` readable._construct(callback) `
2273
- <!-- YAML
2274
- added: v14.13.1
2275
- -->
2276
-
2277
- * ` callback ` {Function} Call this function (optionally with an error
2278
- argument) when the stream has finished initializing.
2279
-
2280
- The ` _construct() ` method MUST NOT be called directly. It may be implemented
2281
- by child classes, and if so, will be called by the internal ` Readable `
2282
- class methods only.
2283
-
2284
- This optional function will be scheduled in the next tick by the stream
2285
- constructor, delaying any ` _read() ` and ` _destroy() ` calls until ` callback ` is
2286
- called. This is useful to initialize state or asynchronously initialize
2287
- resources before the stream can be used.
2288
-
2289
- ``` js
2290
- const { Readable } = require (' stream' );
2291
- const fs = require (' fs' );
2292
-
2293
- class ReadStream extends Readable {
2294
- constructor (filename ) {
2295
- super ();
2296
- this .filename = filename;
2297
- this .fd = null ;
2298
- }
2299
- _construct (callback ) {
2300
- fs .open (this .filename , (fd , err ) => {
2301
- if (err) {
2302
- callback (err);
2303
- } else {
2304
- this .fd = fd;
2305
- callback ();
2306
- }
2307
- });
2308
- }
2309
- _read (n ) {
2310
- const buf = Buffer .alloc (n);
2311
- fs .read (this .fd , buf, 0 , n, null , (err , bytesRead ) => {
2312
- if (err) {
2313
- this .destroy (err);
2314
- } else {
2315
- this .push (bytesRead > 0 ? buf .slice (0 , bytesRead) : null );
2316
- }
2317
- });
2318
- }
2319
- _destroy (err , callback ) {
2320
- if (this .fd ) {
2321
- fs .close (this .fd , (er ) => callback (er || err));
2322
- } else {
2323
- callback (err);
2324
- }
2325
- }
2326
- }
2327
- ```
2328
-
2329
2222
#### ` readable._read(size) `
2330
2223
<!-- YAML
2331
2224
added: v0.9.4
0 commit comments