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


TypeScript core.encode函數代碼示例

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


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

示例1: test

test('checkout subtree', async t => {
  const load = sinon.stub();
  const walkTreeStub = sinon.stub();
  const repo = new CheckoutRepo({load, walkTreeStub});
  load.withArgs('commitHash').resolves({type: Type.commit, body: makeCommit('commit')});
  walkTreeStub.withArgs('treeHash').returns(async function *() : AsyncIterableIterator<HashModePath>{
    yield {
      hash: 'folder1hash',
      mode: Mode.tree,
      path: ['folder']
    };
    yield {
      hash: 'file1Hash',
      mode: Mode.file,
      path: ['folder', 'file.txt']
    };
  }());
  load.withArgs('file1Hash').resolves({type: Type.blob, body: encode('test')});

  const result = await repo.checkoutCommit('commitHash');
  if(!result) return t.fail();
  t.is(result.folders['folder'].hash, 'folder1hash');
  const file1 = result.folders['folder'].files['file.txt'];
  if(!file1) return t.fail();
  t.is(file1.hash, 'file1Hash');
  t.is(file1.text, 'test');
  t.false(file1.isExecutable);
});
開發者ID:strangesast,項目名稱:es-git,代碼行數:28,代碼來源:index.test.ts

示例2: saveFile

    async saveFile(file : File | TextFile | ExistingFile) : Promise<Hash>{
      if(isHash(file)) return file.hash;

      if(isText(file))
        return await super.saveObject({type: Type.blob, body: encode(file.text)});
      else
        return await super.saveObject({type: Type.blob, body: file.body});
    }
開發者ID:strangesast,項目名稱:es-git,代碼行數:8,代碼來源:index.ts

示例3: test

test('load file as string', async t => {
  const load = sinon.stub();
  const repo = new PathToObjectRepo({load});
  load.onCall(0).resolves({type: Type.tree, body: {'file.txt' : {mode: Mode.file, hash: 'fileHash'}}});
  load.onCall(1).resolves({type: Type.blob, body: encode('test')});
  const result = await repo.loadTextByPath('rootHash', 'file.txt');
  if(!result) return t.fail();
  t.is(result, 'test');
});
開發者ID:strangesast,項目名稱:es-git,代碼行數:9,代碼來源:index.test.ts

示例4: joinWithNewline

function joinWithNewline(...values : (string | Uint8Array)[]){
  const sum = values.reduce((sum, x) => sum + x.length, 0);
  const result = new Uint8Array(values.length-1 + sum);
  let offset = 0;
  for (const arr of values) {
    if(offset > 0){
      result.set([NEWLINE], offset++);
    }
    if(typeof(arr) === 'string'){
      result.set(encode(arr), offset);
    }else{
      result.set(arr, offset);
    }
    offset += arr.length;
  }
  return result;
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:17,代碼來源:encodeObject.ts

示例5: pktLine

export default function pktLine(line : Uint8Array | string | null, newline=true){
  if(line === null){
    return new Uint8Array([0x30, 0x30, 0x30, 0x30]);
  }

  const buffer = new Uint8Array(4 + line.length + (newline ? 1 : 0));
  buffer[0] = toHexChar(buffer.length >>> 12);
  buffer[1] = toHexChar((buffer.length >>> 8) & 0xf);
  buffer[2] = toHexChar((buffer.length >>> 4) & 0xf);
  buffer[3] = toHexChar(buffer.length & 0xf);

  if(typeof(line) === 'string'){
    buffer.set(encode(line), 4);
  }else{
    buffer.set(line, 4);
  }

  if(newline){
    buffer[4 + line.length] = NEWLINE;
  }

  return buffer;
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:23,代碼來源:pkt-line.ts

示例6: 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

示例7: fromArray

export function fromArray(lines : Hash[]) : Uint8Array {
  return encode(lines.join('\n'));
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:3,代碼來源:index.ts

示例8: encodeRaw

export function encodeRaw(type : string, bytes : Uint8Array){
  return concat(encode(`${type} ${bytes.length}\0`), bytes);
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:3,代碼來源:normalize-entries.ts

示例9: packHash

 .map(entry => [encode(`${entry.mode.toString(8)} ${entry.name}\0`), packHash(entry.hash)])));
開發者ID:strangesast,項目名稱:es-git,代碼行數:1,代碼來源:encodeObject.ts

示例10: textToBlob

export function textToBlob(text : string) {
  return encode(text);
}
開發者ID:strangesast,項目名稱:es-git,代碼行數:3,代碼來源:encodeObject.ts


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