How to use the bodec.fromArray 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
function packHeader(length : number) {
  return bodec.fromArray([
    0x50, 0x41, 0x43, 0x4b, // PACK
    0, 0, 0, 2,             // version 2
    length >> 24,           // Num of objects
    (length >> 16) & 0xff,
    (length >> 8) & 0xff,
    length & 0xff
  ]);
}
github es-git / es-git / ts / lib / pack-codec.ts View on Github external
}

  if (typeof item.ref === "number") {
    // write BIG_ENDIAN_MODIFIED_BASE_128_NUMBER
    let offset = item.ref;
    // 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);
}