| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -505,6 +505,16 @@ Is `true` after [`writable.end()`][] has been called. This property | |||
| 505 | 505 | does not indicate whether the data has been flushed, for this use | |
| 506 | 506 | [`writable.writableFinished`][] instead. | |
| 507 | 507 | ||
| 508 | + ##### writable.writableCorked | ||
| 509 | + <!-- YAML | ||
| 510 | + added: REPLACEME | ||
| 511 | + --> | ||
| 512 | + | ||
| 513 | + * {integer} | ||
| 514 | + | ||
| 515 | + Number of times [`writable.uncork()`][stream-uncork] needs to be | ||
| 516 | + called in order to fully uncork the stream. | ||
| 517 | + | ||
| 508 | 518 | ##### writable.writableFinished | |
| 509 | 519 | <!-- YAML | |
| 510 | 520 | added: v12.6.0 | |
@@ -2838,6 +2848,7 @@ contain multi-byte characters. | |||
| 2838 | 2848 | [stream-push]: #stream_readable_push_chunk_encoding | |
| 2839 | 2849 | [stream-read]: #stream_readable_read_size | |
| 2840 | 2850 | [stream-resume]: #stream_readable_resume | |
| 2851 | + [stream-uncork]: #stream_writable_uncork | ||
| 2841 | 2852 | [stream-write]: #stream_writable_write_chunk_encoding_callback | |
| 2842 | 2853 | [Stream Three States]: #stream_three_states | |
| 2843 | 2854 | [writable-_destroy]: #stream_writable_destroy_err_callback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,6 @@ const { validateString } = require('internal/validators'); | |||
| 56 | 56 | const HIGH_WATER_MARK = getDefaultHighWaterMark(); | |
| 57 | 57 | const { CRLF, debug } = common; | |
| 58 | 58 | ||
| 59 | - const kIsCorked = Symbol('isCorked'); | ||
| 60 | - | ||
| 61 | 59 | const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i; | |
| 62 | 60 | const RE_TE_CHUNKED = common.chunkExpression; | |
| 63 | 61 | ||
@@ -101,7 +99,6 @@ function OutgoingMessage() { | |||
| 101 | 99 | ||
| 102 | 100 | this.finished = false; | |
| 103 | 101 | this._headerSent = false; | |
| 104 | - this[kIsCorked] = false; | ||
| 105 | 102 | ||
| 106 | 103 | this.socket = null; | |
| 107 | 104 | this._header = null; | |
@@ -628,10 +625,9 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | |||
| 628 | 625 | ['string', 'Buffer'], chunk); | |
| 629 | 626 | } | |
| 630 | 627 | ||
| 631 | - if (!fromEnd && msg.socket && !msg[kIsCorked]) { | ||
| 628 | + if (!fromEnd && msg.socket && !msg.socket.writableCorked) { | ||
| 632 | 629 | msg.socket.cork(); | |
| 633 | - msg[kIsCorked] = true; | ||
| 634 | - process.nextTick(connectionCorkNT, msg, msg.socket); | ||
| 630 | + process.nextTick(connectionCorkNT, msg.socket); | ||
| 635 | 631 | } | |
| 636 | 632 | ||
| 637 | 633 | var len, ret; | |
@@ -660,8 +656,7 @@ function writeAfterEndNT(msg, err, callback) { | |||
| 660 | 656 | } | |
| 661 | 657 | ||
| 662 | 658 | ||
| 663 | - function connectionCorkNT(msg, conn) { | ||
| 664 | - msg[kIsCorked] = false; | ||
| 659 | + function connectionCorkNT(conn) { | ||
| 665 | 660 | conn.uncork(); | |
| 666 | 661 | } | |
| 667 | 662 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -385,6 +385,16 @@ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { | |||
| 385 | 385 | } | |
| 386 | 386 | }); | |
| 387 | 387 | ||
| 388 | + Object.defineProperty(Writable.prototype, 'writableCorked', { | ||
| 389 | + // Making it explicit this property is not enumerable | ||
| 390 | + // because otherwise some prototype manipulation in | ||
| 391 | + // userland will fail | ||
| 392 | + enumerable: false, | ||
| 393 | + get: function() { | ||
| 394 | + return this._writableState ? this._writableState.corked : 0; | ||
| 395 | + } | ||
| 396 | + }); | ||
| 397 | + | ||
| 388 | 398 | // If we're already writing something, then just put this | |
| 389 | 399 | // in the queue, and wait our turn. Otherwise, call _write | |
| 390 | 400 | // If we return false, then we need a drain event, so set that flag. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + const { Writable } = require('stream'); | ||
| 6 | + | ||
| 7 | + { | ||
| 8 | + const w = new Writable(); | ||
| 9 | + assert.strictEqual(w.writableCorked, 0); | ||
| 10 | + w.uncork(); | ||
| 11 | + assert.strictEqual(w.writableCorked, 0); | ||
| 12 | + w.cork(); | ||
| 13 | + assert.strictEqual(w.writableCorked, 1); | ||
| 14 | + w.cork(); | ||
| 15 | + assert.strictEqual(w.writableCorked, 2); | ||
| 16 | + w.uncork(); | ||
| 17 | + assert.strictEqual(w.writableCorked, 1); | ||
| 18 | + w.uncork(); | ||
| 19 | + assert.strictEqual(w.writableCorked, 0); | ||
| 20 | + w.uncork(); | ||
| 21 | + assert.strictEqual(w.writableCorked, 0); | ||
| 22 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments