Upgrade to Pro — share decks privately, control downloads, hide ads and more …

大量塩基配列登録申請システムができるまで

Keita Urashima
October 21, 2022
2.6k

 大量塩基配列登録申請システムができるまで

Keita Urashima

October 21, 2022
Tweet

Transcript

  1. <input type="file" /> <script> document.querySelector('input') .addEventListener('change', async (e) => {

    const file = e.target.files[0]; const reader = file.stream().getReader(); for (;;) { const {done, value} = await reader.read(); if (done) { break; } console.log(value); } }); </script>
  2. const LF = '\n'.codePointAt(0); const CR = '\r'.codePointAt(0); const GT

    = '>'.codePointAt(0); async function parse(file) { const reader = file.stream().getReader(); let done, value; let entriesCount = 0; let isBOL = true; while (({done, value} = await reader.read()), !done) { for (const byte of value) { if (isBOL && byte === GT) { entriesCount++; isBOL = false; } else { isBOL = byte === LF || byte === CR; } } } return {entriesCount}; }
  3. const worker = new Worker('./worker.js'); worker.addEventListener('message', e => { console.log(e.data);

    }); worker.postMessage('hello, world'); addEventListener('message', e => { postMessage(e.data.toUpperCase()); }); NBJOKT XPSLFSKT ᶃ ᶄ ᶅ ᶆ
  4. addEventListener('message', async ({data: {file}}) => { try { const payload

    = await parse(file); postMessage([null, payload]); } catch (err) { postMessage([err, null]); } }); async function parse(file) { const reader = file.stream().getReader(); // ... return {entriesCount}; }