arnaucube
arnaucube/circomPublic Self-hosted repository
circom/src/streamfromarray_bin.js
src/streamfromarray_bin.jsRaw
 1
 2const Readable = require("stream").Readable;
 3
 4module.exports = function streamFromArrayBin(a) {
 5    const  rs = Readable();
 6
 7    let curIndex = 0;
 8
 9    rs._read = function(size) {
10        if (curIndex >= a.length) {
11            rs.push(null);
12            return;
13        }
14        const start = curIndex;
15        const end = Math.min(a.length, curIndex+size);
16        curIndex = end;
17        rs.push(a.slice(start, end));
18    };
19
20    return rs;
21};