本文整理汇总了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;未经允许,请勿转载。 |
请发表评论