How to use the bodec.create 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 / mixins / github-db.js View on Github external
var decoders = {
  commit: decodeCommit,
  tag: decodeTag,
  tree: decodeTree,
  blob: decodeBlob,
};

// Precompute hashes for empty blob and empty tree since github won't
var emptyBlob = sha1(frame({
  type: "blob",
  body: binary.create(0)
}));
var emptyTree = sha1(frame({
  type: "tree",
  body: binary.create(0)
}));

// Implement the js-git object interface using github APIs
module.exports = function (repo, root, accessToken) {

  var apiRequest = xhr(root, accessToken);

  repo.loadAs = loadAs;         // (type, hash) -> value, hash
  repo.saveAs = saveAs;         // (type, value) -> hash, value
  repo.readRef = readRef;       // (ref) -> hash
  repo.updateRef = updateRef;   // (ref, hash) -> hash
  repo.createTree = createTree; // (entries) -> hash, tree
  repo.hasHash = hasHash;

  function loadAs(type, hash, callback) {
    // Github doesn't like empty trees, but we know them already.
github digidem / react-mapfilter / app / js / lib / backbone-github.js View on Github external
tag: encodeTag,
  tree: encodeTree,
  blob: encodeBlob
};

var decoders = {
  commit: decodeCommit,
  tag: decodeTag,
  tree: decodeTree,
  blob: decodeBlob,
};

var typeCache = {};

// Precompute hashes for empty blob and empty tree since github won't
var empty = bodec.create(0);
var emptyBlob = sha1(frame({ type: "blob", body: empty }));
var emptyTree = sha1(frame({ type: "tree", body: empty }));

// Implement the js-git object interface using github APIs
module.exports = function (repo, root, accessToken) {

  var apiRequest = xhr(root, accessToken);

  repo.loadAs = loadAs;         // (type, hash) -> value, hash
  repo.saveAs = saveAs;         // (type, value) -> hash, value
  repo.readRef = readRef;       // (ref) -> hash
  repo.updateRef = updateRef;   // (ref, hash) -> hash
  repo.createTree = createTree; // (entries) -> hash, tree
  repo.hasHash = hasHash;

  function loadAs(type, hash, callback) {
github es-git / es-git / ts / lib / pkt-line.ts View on Github external
state = -1;
          throw new SyntaxError("Not a hex char: " + String.fromCharCode(byte));
        }
        length |= val << ((--offset) * 4);
        if (offset === 0) {
          if (length === 4) {
            offset = 4;
            more = emit("");
          }
          else if (length === 0) {
            offset = 4;
            more = emit(null);
          }
          else if (length > 4) {
            length -= 4;
            data = bodec.create(length);
            state = 1;
          }
          else {
            state = -1;
            throw new SyntaxError("Invalid length: " + length);
          }
        }
      }
      else if (state === 1) {
        data[offset++] = byte;
        if (offset === length) {
          offset = 4;
          state = 0;
          length = 0;
          if (data[0] === 1) {
            more = emit(bodec.slice(data, 1));
github creationix / http-codec / http-codec.js View on Github external
function $chunkStart(byte) {
    if (byte === 0x0a) {
      if (size) {
        chunk = bodec.create(size);
        return $chunk;
      }
      return $ending;
    }
    throw new SyntaxError("Invalid chunk ending");
  }
github mjackson / mach / modules / multipart / Parser.js View on Github external
function Parser(boundary, partHandler) {
  this.boundary = bodec.fromRaw('\r\n--' + boundary);
  this.lookBehind = bodec.create(this.boundary.length + 8);
  this.boundaryChars = {};

  var i = this.boundary.length;
  while (i)
    this.boundaryChars[this.boundary[--i]] = true;

  this.state = S.START;
  this.index = null;
  this.flags = 0;

  if (typeof partHandler !== 'function')
    throw new Error('multipart.Parser needs a part handler');

  this.onPart = partHandler;
}
github mjackson / mach / build / npm / multipart / Parser.js View on Github external
function Parser(boundary, partHandler) {
  this.boundary = bodec.fromRaw("\r\n--" + boundary);
  this.lookBehind = bodec.create(this.boundary.length + 8);
  this.boundaryChars = {};

  var i = this.boundary.length;
  while (i) this.boundaryChars[this.boundary[--i]] = true;

  this.state = S.START;
  this.index = null;
  this.flags = 0;

  if (typeof partHandler !== "function") throw new Error("multipart.Parser needs a part handler");

  this.onPart = partHandler;
}
github es-git / es-git / ts / lib / pkt-line.ts View on Github external
function frameHead(length : number) {
  const buffer = bodec.create(4);
  buffer[0] = toHexChar(length >>> 12);
  buffer[1] = toHexChar((length >>> 8) & 0xf);
  buffer[2] = toHexChar((length >>> 4) & 0xf);
  buffer[3] = toHexChar(length & 0xf);
  return buffer;
}