| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -502,6 +502,16 @@ Is `true` after [`writable.end()`][] has been called. This property | |||
| 502 | 502 | does not indicate whether the data has been flushed, for this use | |
| 503 | 503 | [`writable.writableFinished`][] instead. | |
| 504 | 504 | ||
| 505 | + ##### `writable.writableCorked` | ||
| 506 | + <!-- YAML | ||
| 507 | + added: REPLACEME | ||
| 508 | + --> | ||
| 509 | + | ||
| 510 | + * {integer} | ||
| 511 | + | ||
| 512 | + Number of times [`writable.uncork()`][stream-uncork] needs to be | ||
| 513 | + called in order to fully uncork the stream. | ||
| 514 | + | ||
| 505 | 515 | ##### `writable.writableFinished` | |
| 506 | 516 | <!-- YAML | |
| 507 | 517 | added: v12.6.0 | |
@@ -2842,6 +2852,7 @@ contain multi-byte characters. | |||
| 2842 | 2852 | [stream-push]: #stream_readable_push_chunk_encoding | |
| 2843 | 2853 | [stream-read]: #stream_readable_read_size | |
| 2844 | 2854 | [stream-resume]: #stream_readable_resume | |
| 2855 | + [stream-uncork]: #stream_writable_uncork | ||
| 2845 | 2856 | [stream-write]: #stream_writable_write_chunk_encoding_callback | |
| 2846 | 2857 | [Stream Three States]: #stream_three_states | |
| 2847 | 2858 | [writable-_destroy]: #stream_writable_destroy_err_callback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,8 +55,6 @@ const { validateString } = require('internal/validators'); | |||
| 55 | 55 | const HIGH_WATER_MARK = getDefaultHighWaterMark(); | |
| 56 | 56 | const { CRLF, debug } = common; | |
| 57 | 57 | ||
| 58 | - const kIsCorked = Symbol('isCorked'); | ||
| 59 | - | ||
| 60 | 58 | const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i; | |
| 61 | 59 | const RE_TE_CHUNKED = common.chunkExpression; | |
| 62 | 60 | ||
@@ -100,7 +98,6 @@ function OutgoingMessage() { | |||
| 100 | 98 | ||
| 101 | 99 | this.finished = false; | |
| 102 | 100 | this._headerSent = false; | |
| 103 | - this[kIsCorked] = false; | ||
| 104 | 101 | ||
| 105 | 102 | this.socket = null; | |
| 106 | 103 | this.connection = null; | |
@@ -619,9 +616,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | |||
| 619 | 616 | ['string', 'Buffer'], chunk); | |
| 620 | 617 | } | |
| 621 | 618 | ||
| 622 | - if (!fromEnd && msg.connection && !msg[kIsCorked]) { | ||
| 619 | + if (!fromEnd && msg.connection && !msg.connection.writableCorked) { | ||
| 623 | 620 | msg.connection.cork(); | |
| 624 | - msg[kIsCorked] = true; | ||
| 625 | 621 | process.nextTick(connectionCorkNT, msg, msg.connection); | |
| 626 | 622 | } | |
| 627 | 623 | ||
@@ -651,8 +647,7 @@ function writeAfterEndNT(msg, err, callback) { | |||
| 651 | 647 | } | |
| 652 | 648 | ||
| 653 | 649 | ||
| 654 | - function connectionCorkNT(msg, conn) { | ||
| 655 | - msg[kIsCorked] = false; | ||
| 650 | + function connectionCorkNT(conn) { | ||
| 656 | 651 | conn.uncork(); | |
| 657 | 652 | } | |
| 658 | 653 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -379,6 +379,16 @@ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { | |||
| 379 | 379 | } | |
| 380 | 380 | }); | |
| 381 | 381 | ||
| 382 | + Object.defineProperty(Writable.prototype, 'writableCorked', { | ||
| 383 | + // Making it explicit this property is not enumerable | ||
| 384 | + // because otherwise some prototype manipulation in | ||
| 385 | + // userland will fail | ||
| 386 | + enumerable: false, | ||
| 387 | + get: function() { | ||
| 388 | + return this._writableState ? this._writableState.corked : 0; | ||
| 389 | + } | ||
| 390 | + }); | ||
| 391 | + | ||
| 382 | 392 | // If we're already writing something, then just put this | |
| 383 | 393 | // in the queue, and wait our turn. Otherwise, call _write | |
| 384 | 394 | // 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