How to use the bodec.join function in bodec

To help you get started, we’ve selected a few bodec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github es-git / es-git / ts / lib / pack-codec.ts View on Github external
// Calculate how many digits we need in base 128 and move the pointer
    i += Math.floor(Math.log(offset) / Math.log(0x80)) + 1;
    // Write the last digit
    head[i] = offset & 0x7f;
    // Then write the rest
    while (offset >>= 7) {
      head[--i] = 0x80 | (--offset & 0x7f);
    }
  }

  const parts = [bodec.fromArray(head)];
  if (typeof item.ref === "string") {
    parts.push(bodec.fromHex(item.ref));
  }
  parts.push(deflate(item.body));
  return bodec.join(parts);
}
github es-git / es-git / test / test-pack-codec.js View on Github external
}
      if (!bodec.isBinary(item)) throw new Error("encode output must be buffers");
      outs.push(item);
    });
    write({num:items.length});
    items.forEach(item => {
      if (!bodec.isBinary(item.body)) {
        item.body = encoders[item.type](item.body);
        }
      write(item);
    });
    write();

    if (!done) throw new Error("Output stream never ended");

    newPack = bodec.join(outs);
  },
  function verifyEncodePack() {
github es-git / es-git / ts / lib / pkt-line.ts View on Github external
more = emit({progress: bodec.toUnicode(data, 1)});
          }
          else if (data[0] === 3) {
            more = emit({error: bodec.toUnicode(data, 1)});
          }
          else {
            more = emit(bodec.toUnicode(data).trim());
          }
        }
      }
      else if (state === 2) {
        if (offset < 4 && byte === PACK[offset++]) {
          continue;
        }
        state = 3;
        more = emit(bodec.join([PACK, bodec.subarray(item, i)]));
        break;
      }
      else {
        throw new Error("pkt-line decoder in invalid state");
      }
    }

    return more;
  };
github mjackson / bufferedstream / specs / BufferedStream-spec.js View on Github external
function stringifyData(data) {
  return binaryTo(require('bodec').join(data));
}
github mjackson / mach / build / npm / utils / bufferStream.js View on Github external
stream.on("end", function () {
      resolve(bodec.join(chunks));
    });
github es-git / es-git / ts / net / transport-http.ts View on Github external
function onWrite(item) {
        if (item === undefined) return socket.put();
        bodyWrite(item);
        socket.take(onWrite);
        if (item !== "done\n" || !bodyParts.length) return;
        const body = bodec.join(bodyParts);
        bodyParts.length = 0;
        request("POST", gitUrl + "/" + serviceName, headers, body, onResult);
      }
github es-git / es-git / ts / lib / pack-codec.ts View on Github external
function emitObject() {
    const body = bodec.join(parts);
    if (body.length !== length) {
      throw new Error("Body length mismatch");
    }
    const item : any = {
      type: numToType[type],
      size: length,
      body: body,
      offset: start
    };
    if (ref) item.ref = ref;
    parts.length = 0;
    start = 0;
    offset = 0;
    type = 0;
    length = 0;
    ref = 0;
github digidem / react-mapfilter / app / js / lib / backbone-github.js View on Github external
function frame(obj) {
  var type = obj.type;
  var body = obj.body;
  if (!bodec.isBinary(body)) body = encoders[type](body);
  return bodec.join([
    bodec.fromRaw(type + " " + body.length + "\0"),
    body
  ]);
}
github es-git / es-git / ts / lib / object-codec.ts View on Github external
function frame(obj : Frame) {
  const type = obj.type;
  const body = bodec.isBinary(obj.body) ? obj.body : (encoders as any)[type](obj.body) as Uint8Array;
  return bodec.join([
    bodec.fromRaw(type + " " + body.length + "\0"),
    body
  ]);
}