• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.decode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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: '[email protected]',
       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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.encode函数代码示例发布时间:2022-05-28
下一篇:
TypeScript core.concat函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap