亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

writable.cork()方法用于強(qiáng)制所有寫入的數(shù)據(jù)緩沖在內(nèi)存中。只有在調(diào)用stream.uncork()或stream.end()方法后,緩沖數(shù)據(jù)才會(huì)從緩沖存儲(chǔ)器中刪除。

語(yǔ)法

cork()

writeable.cork()

登錄后復(fù)制

開(kāi)塞()

writeable.uncork()

登錄后復(fù)制

參數(shù)

因?yàn)樗彌_寫入的數(shù)據(jù)。唯一需要的參數(shù)將是可寫數(shù)據(jù)。

示例

創(chuàng)建一個(gè)名為 cork.js 的文件并復(fù)制以下代碼片段。創(chuàng)建文件后,使用以下命令運(yùn)行此代碼,如下例所示 –

node cork.js

登錄后復(fù)制

cork.js

?現(xiàn)場(chǎng)演示

// Program to demonstrate writable.cork() method
const stream = require('stream');

// Creating a data stream with writable
const writable = new stream.Writable({
   // Writing the data from stream
   write: function(chunk, encoding, next) {
      // Converting the data chunk to be displayed
      console.log(chunk.toString());
      next();
   }
});

// Writing data
writable.write('Hi - This data is printed');

// Calling the cork() function
writable.cork();

// Again writing some data
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
writable.write('This data will be corked in the memory');

登錄后復(fù)制

輸出

C:\homeode>> node cork.js
Hi - This data is printed

登錄后復(fù)制

只有在 cork() 方法之間寫入的數(shù)據(jù)才會(huì)被打印,而其余數(shù)據(jù)將被塞入緩沖存儲(chǔ)器中。下面的示例展示了如何從緩沖區(qū)內(nèi)存中解鎖上述數(shù)據(jù)。

示例

讓我們?cè)倏匆粋€(gè)有關(guān)如何 uncork() 的示例 – uncork.js

?現(xiàn)場(chǎng)演示

// Program to demonstrate writable.cork() method
const stream = require('stream');

// Creating a data stream with writable
const writable = new stream.Writable({
   // Writing the data from stream
   write: function(chunk, encoding, next) {
      // Converting the data chunk to be displayed
      console.log(chunk.toString());
      next();
   }
});

// Writing data
writable.write('Hi - This data is printed');

// Calling the cork() function
writable.cork();

// Again writing some data
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
writable.write('This data will be corked in the memory');

// Flushing the data from buffered memory
writable.uncork()

登錄后復(fù)制

輸出

C:\homeode>> node uncork.js
Hi - This data is printed
Welcome to TutorialsPoint !
SIMPLY LEARNING
This data will be corked in the memory

登錄后復(fù)制

使用 uncork() 方法刷新緩沖內(nèi)存后,就會(huì)顯示上面示例中的完整數(shù)據(jù)。

以上就是Node.js 中的 Stream writable.cork() 和 uncork() 方法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!

分享到:
標(biāo)簽:JS Node Stream uncork 方法
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定