How to use the bodec.js.slice 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 creationix / tedit / src / js-git / mixins / fs-db.js View on Github external
throw new Error("Only v2 pack indexes supported");
  }

  // Get the number of hashes in index
  // This is the value of the last fan-out entry
  var hashOffset = 8 + 255 * 4;
  var length = readUint32(buffer, hashOffset);
  hashOffset += 4;
  var crcOffset = hashOffset + 20 * length;
  var lengthOffset = crcOffset + 4 * length;
  var largeOffset = lengthOffset + 4 * length;
  var checkOffset = largeOffset;
  var indexes = new Array(length);
  for (var i = 0; i < length; i++) {
    var start = hashOffset + i * 20;
    var hash = bodec.toHex(bodec.slice(buffer, start, start + 20));
    var crc = readUint32(buffer, crcOffset + i * 4);
    var offset = readUint32(buffer, lengthOffset + i * 4);
    if (offset & 0x80000000) {
      offset = largeOffset + (offset &0x7fffffff) * 8;
      checkOffset = Math.max(checkOffset, offset + 8);
      offset = readUint64(buffer, offset);
    }
    indexes[i] = {
      hash: hash,
      offset: offset,
      crc: crc
    };
  }
  var packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
  var checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
  if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
github creationix / tedit / src / js-git / mixins / fs-db.js View on Github external
var crc = readUint32(buffer, crcOffset + i * 4);
    var offset = readUint32(buffer, lengthOffset + i * 4);
    if (offset & 0x80000000) {
      offset = largeOffset + (offset &0x7fffffff) * 8;
      checkOffset = Math.max(checkOffset, offset + 8);
      offset = readUint64(buffer, offset);
    }
    indexes[i] = {
      hash: hash,
      offset: offset,
      crc: crc
    };
  }
  var packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
  var checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
  if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
    throw new Error("Checksum mistmatch");
  }

  var byHash = {};
  indexes.sort(function (a, b) {
    return a.offset - b.offset;
  });
  indexes.forEach(function (data) {
    byHash[data.hash] = {
      offset: data.offset,
      crc: data.crc,
    };
  });
  var offsets = indexes.map(function (entry) {
    return entry.offset;
  }).sort(function (a, b) {
github creationix / tedit / src / js-git / mixins / fs-db.js View on Github external
var start = hashOffset + i * 20;
    var hash = bodec.toHex(bodec.slice(buffer, start, start + 20));
    var crc = readUint32(buffer, crcOffset + i * 4);
    var offset = readUint32(buffer, lengthOffset + i * 4);
    if (offset & 0x80000000) {
      offset = largeOffset + (offset &0x7fffffff) * 8;
      checkOffset = Math.max(checkOffset, offset + 8);
      offset = readUint64(buffer, offset);
    }
    indexes[i] = {
      hash: hash,
      offset: offset,
      crc: crc
    };
  }
  var packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
  var checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
  if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
    throw new Error("Checksum mistmatch");
  }

  var byHash = {};
  indexes.sort(function (a, b) {
    return a.offset - b.offset;
  });
  indexes.forEach(function (data) {
    byHash[data.hash] = {
      offset: data.offset,
      crc: data.crc,
    };
  });
  var offsets = indexes.map(function (entry) {
github creationix / tedit / src / js-git / mixins / fs-db.js View on Github external
var hash = bodec.toHex(bodec.slice(buffer, start, start + 20));
    var crc = readUint32(buffer, crcOffset + i * 4);
    var offset = readUint32(buffer, lengthOffset + i * 4);
    if (offset & 0x80000000) {
      offset = largeOffset + (offset &0x7fffffff) * 8;
      checkOffset = Math.max(checkOffset, offset + 8);
      offset = readUint64(buffer, offset);
    }
    indexes[i] = {
      hash: hash,
      offset: offset,
      crc: crc
    };
  }
  var packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
  var checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
  if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
    throw new Error("Checksum mistmatch");
  }

  var byHash = {};
  indexes.sort(function (a, b) {
    return a.offset - b.offset;
  });
  indexes.forEach(function (data) {
    byHash[data.hash] = {
      offset: data.offset,
      crc: data.crc,
    };
  });
  var offsets = indexes.map(function (entry) {
    return entry.offset;