<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ``` //1) 自定義可寫流 let {Readable} = require('stream'); // 想實現什么流 就繼承這個流 // Readable 里面有一個 read() 方法,默認調_read(); // Readable中提供了一個push方法,你調用push方法就會觸發data事件 // let index = 9; // class MyRead extends Readable{ // _read(){ // // 可讀流什么時候停止呢? 當push null的時候停止 // if(index-->0)return this.push('123'); // this.push(null); // } // } // let mr = new MyRead; // mr.on('data',function(data){ // console.log(data); // }); // --- --- --- //2) 自定義可寫流 let {Writable} = require('stream'); // 可寫流實現_write方法 // 源碼中默認調用的是Writable中的write方法 // class MyWrite extends Writable{ // _write(chunk,encoding,callback){ // console.log(chunk.toString()); // callback(); // clearBuffer() // } // } // let mw = new MyWrite(); // mw.write('珠峰','utf8',()=>{ // console.log(1); // }) // mw.write('珠峰','utf8',()=>{ // console.log(1); // }) // --- --- --- //3) Duplex雙工流 let {Duplex} = require('stream'); // 雙工流 又能讀 又能寫,而且讀寫可以沒關系 // class D extends Duplex{ // _read(){ // } // _write(){ // } // } // let d = Duplex({ // read(){ //等同于上面的_read // this.push('hello'); // this.push(null); // } // ,write(chunk,encoding,callback){ // console.log(chunk); // callback(); // } // }) // d.on('data',function(data){ // console.log(data); //<Buffer 68 65 6c 6c 6f> // }) // d.write('world'); // <Buffer 77 6f 72 6c 64> //可以只實現一個 讀或則寫 // --- --- --- //4) transform流 他就是Duplex 但它不需要實現read和write,它實現的是transform let {Transform} = require('stream'); // 他的參數和可寫流一樣 let transform1 = Transform({ transform(chunk,encoding,callback){ // console.log(chunk); //<Buffer 31 0d 0a> // 0d \r 0a \n // callback(); //必須調 不然卡死 //類似于next this.push(chunk.toString().toUpperCase()); // 將輸入的內容放入到可讀流中 callback(); //比填 } }); let transform2 = Transform({ transform(chunk,encoding,callback){ console.log(chunk.toString()); callback(); } }); // 等待你輸入 // rs.pipe(ws); process.stdin.pipe(transform1).pipe(transform2) // 可讀流里只能放 buffer 或則 字符串 對象流里可以放對象 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看