本文整理匯總了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);
});
示例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});
}
示例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');
});
示例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;
}
示例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;
}
示例6: testPktLine
function testPktLine(t : TestContext, input : string, expected : string) {
t.is(decode(pktLine(encode(input))), expected);
}
示例7: fromArray
export function fromArray(lines : Hash[]) : Uint8Array {
return encode(lines.join('\n'));
}
示例8: encodeRaw
export function encodeRaw(type : string, bytes : Uint8Array){
return concat(encode(`${type} ${bytes.length}\0`), bytes);
}
示例9: packHash
.map(entry => [encode(`${entry.mode.toString(8)} ${entry.name}\0`), packHash(entry.hash)])));
示例10: textToBlob
export function textToBlob(text : string) {
return encode(text);
}