1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        oput前端數(shù)據(jù)零存整取工具庫

        聯(lián)合創(chuàng)作 · 2023-09-29 14:02

        oput 是一個用于前端讀取預(yù)定長度數(shù)據(jù)的工具庫,相當(dāng)于零存整?。? put do)

        • 零存代表,異步獲取到的數(shù)據(jù)是零碎的,且長度不確定(例如tcp流的數(shù)據(jù))
        • 整取代表,需要讀取的數(shù)據(jù)的長度是確定的。

        比如有一個場景,每次采集到的數(shù)據(jù)是128個字節(jié),但是我需要湊滿480個字節(jié)使用,那么就需要做緩存,生產(chǎn)和消費(fèi),更新緩存。

        oput將這種行為封裝起來,減少重復(fù)編寫類似的代碼。

        具體使用方式:

        生產(chǎn)者:

        通過write方法填充數(shù)據(jù),接收TypedArray和ArrayBuffer類型的數(shù)據(jù)

        import OPut from 'oput'
        const oput = new OPut(reader)
        oput.write(new Uint32Array([1,2,3]))

        消費(fèi)者:

        方式1、按字節(jié)讀?。?/p>

        function *reader(){
          let b = yield 5;//讀取5個字節(jié)
          console.log(b[0])
        }

        方式2、用TypedArray作為容器讀取

        function *reader(){
          let b = new Uint8Array(5);
          yield b;//填充到b中
          console.log(b[0])
          b = new Uint32Array(5);
          yield b;//填充到b中,又讀取了20個字節(jié)
          console.log(b[0])
        }

        方式3、read方法異步讀取

          const oput = new OPut();
          oput.write(new Uint32Array([1, 2]));
          oput.write(new Uint32Array([1, 2]));
          oput.read(1).then(value=>{
            expect(value[0]).toBe(1)
            return oput.read(4)
          }).then(value=>{
            expect(value[3]).toBe(2)
          })

         

        瀏覽 21
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            在线免费观看黄色小视频 | 日韩男女操逼视频 | 扒美女内裤摸下部 | 放荡的少妇2做爰免费观看 | 日韩一级黄色片 | 德国黄色一级片 | 国产黄色在线看 | 天天综合一区二区三区 | 韩国少妇性xxxx少妇 | 《色戒》汤唯无删减版视频 |