當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.decode函數代碼示例

本文整理匯總了TypeScript中@es-git/core.decode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript decode函數的具體用法?TypeScript decode怎麽用?TypeScript decode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了decode函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: toArray

export function toArray(contents : Uint8Array | undefined){
  if(!contents){
    return []
  }

  return decode(contents).split('\n');
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:7,代碼來源:index.ts

示例2: collect

async function collect(iterator : AsyncIterableIterator<RawObject>){
  const result : string[] = [];
  for await(const item of iterator){
    result.push(decode(item.body));
  }
  return result
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:7,代碼來源:index.test.ts

示例3: decodeTree

function decodeTree(body : Uint8Array) : TreeObject {
  let i = 0;
  const length = body.length;
  let start;
  let mode;
  let name;
  let hash;
  const tree : TreeBody = {};
  while (i < length) {
    start = i;
    i = body.indexOf(0x20, start);
    if (i < 0) throw new SyntaxError("Missing space");
    mode = fromOct(body, start, i++);
    start = i;
    i = body.indexOf(0x00, start);
    name = decode(body, start, i++);
    hash = unpackHash(body, i, i += 20);
    tree[name] = {
      mode: mode,
      hash: hash
    };
  }

  return {
    type: Type.tree,
    body: tree
  };
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:28,代碼來源:decodeObject.ts

示例4: test

 async test() {
   const dir = await this.checkout('refs/heads/master');
   console.log(dir);
   const newHash = await this.commit(
     'refs/heads/master',
     {
       files: dir.files,
       folders: {
         ...dir.folders,
         'src': {
           files: {
             'index.js': {
               mode: Mode.file,
               text: 'console.log(hello)'
             }
           }
         }
       },
     },
     'second test commit',
     {
       name: 'Marius Gundersen',
       email: 'me@mariusgundersen.net',
       date: new Date()
     });
   console.log(newHash);
   const commit = await this.loadObject(newHash);
   if(!commit || commit.type != Type.commit) throw new Error("shouldn't happen");
   const result = await this.loadObjectByPath(commit.body.tree, ['src', 'index.js']);
   if(result && result.type === Type.blob){
     console.log(decode(result.body));
   }
 }
開發者ID:strangesast,項目名稱:es-git,代碼行數:33,代碼來源:index.ts

示例5: await

async function *toRawObject(objects : AsyncIterableIterator<HashBlob>) : AsyncIterableIterator<RawObject> {
  for await(const [hash, body] of objects){
    const space = body.indexOf(0x20)
    const nil = body.indexOf(0x00, space);
    yield {
      body: body.subarray(nil+1),
      type: decode(body, 0, space),
      hash: hash
    }
  }
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:11,代碼來源:pack.ts

示例6: recursivelyMakeFile

function recursivelyMakeFile(parent : PartialFolder, path : string[], isExecutable : boolean, hash : Hash, body : Uint8Array){
  const [name, ...subPath] = path;
  if(subPath.length === 0){
    parent.files[name] = {
      hash,
      isExecutable,
      body,
      get text(){return decode(body)}
    }
  }else{
    recursivelyMakeFile(parent.folders[name], subPath, isExecutable, hash, body);
  }
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:13,代碼來源:index.ts

示例7: decodeCommit

function decodeCommit(body : Uint8Array) : CommitObject {
  let i = 0;
  let start;
  let key : keyof CommitBody | 'parent';
  const parents : string[] = [];
  const commit : any = {
    tree: "",
    parents: parents,
    author: undefined,
    committer: undefined,
    message: ""
  };
  while (body[i] !== 0x0a) {
    start = i;
    i = body.indexOf(0x20, start);
    if (i < 0) throw new SyntaxError("Missing space");
    key = decode(body, start, i++) as any;
    start = i;
    i = body.indexOf(0x0a, start);
    if (i < 0) throw new SyntaxError("Missing linefeed");
    let value = decode(body, start, i++);
    if (key === "parent") {
      parents.push(value);
    } else if (key === "author" || key === "committer") {
      commit[key] = decodePerson(value);
    } else {
      commit[key] = value;
    }
  }
  i++;
  commit.message = decode(body, i, body.length);
  return {
    type: Type.commit,
    body: commit
  };
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:36,代碼來源:decodeObject.ts

示例8: decodeTag

function decodeTag(body : Uint8Array) : TagObject {
  let i = 0;
  let start;
  let key;
  const tag : any = {};
  while (body[i] !== 0x0a) {
    start = i;
    i = body.indexOf(0x20, start);
    if (i < 0) throw new SyntaxError("Missing space");
    key = decode(body, start, i++);
    start = i;
    i = body.indexOf(0x0a, start);
    if (i < 0) throw new SyntaxError("Missing linefeed");
    let value : any = decode(body, start, i++);
    if (key === "tagger") value = decodePerson(value);
    tag[key] = value;
  }
  i++;
  tag.message = decode(body, i, body.length);
  return {
    type: Type.tag,
    body: tag
  };
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:24,代碼來源:decodeObject.ts

示例9: decodeObject

export default function decodeObject(buffer : Uint8Array) : GitObject {
  const space = buffer.indexOf(0x20);
  if (space < 0) throw new Error("Invalid git object buffer");
  const nil = buffer.indexOf(0x00, space);
  if (nil < 0) throw new Error("Invalid git object buffer");
  const body = buffer.subarray(nil + 1);
  const size = fromDec(buffer, space + 1, nil);
  if (size !== body.length) throw new Error("Invalid body length.");
  const type = decode(buffer, 0, space);
  switch(type){
    case Type.blob:
      return decodeBlob(body);
    case Type.tree:
      return decodeTree(body);
    case Type.commit:
      return decodeCommit(body);
    case Type.tag:
      return decodeTag(body);
    default:
      throw new Error("Unknown type");
  }
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:22,代碼來源:decodeObject.ts

示例10: testPktLine

function testPktLine(t : TestContext, input : string, expected : string) {
  t.is(decode(pktLine(encode(input))), expected);
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:3,代碼來源:pkt-line.test.ts


注:本文中的@es-git/core.decode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。