本文整理汇总了TypeScript中buffer.Buffer.toString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Buffer.toString方法的具体用法?TypeScript Buffer.toString怎么用?TypeScript Buffer.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: decode
export function decode(data: Buffer, encoding?: string): any {
let value: string;
let rest: Buffer
({ value, rest } = _decode(data, encoding));
if (rest.length) {
throw new Error(`Unexpected continuation: "${rest.toString()}"`)
}
return value;
}
示例2: function
const streamWrite: NodeJS.WritableStream['write'] = function (chunk: Buffer | string, encoding?: any, callback?: Function) {
if (Buffer.isBuffer(chunk)) {
chunk = chunk.toString(encoding)
}
process.log(chunk)
if (callback) {
callback()
}
return true
}
示例3: decodeString
function decodeString(data: Buffer, encoding?: string): DecodingResult {
let firstColonIndex = null;
for (let i = 0; i < data.length; i++) {
if (data[i] === Delimeters.colon) {
firstColonIndex = i;
break;
}
}
if (!firstColonIndex) {
throw new Error(`Error while decoding ${data.toString(encoding)}. Missing colon.`);
}
let expectedLength = parseInt(data.slice(0, firstColonIndex).toString());
let value = data.slice(firstColonIndex + 1, firstColonIndex + 1 + expectedLength);
return { value: value.toString(encoding), rest: data.slice(firstColonIndex + 1 + expectedLength) }
}
示例4: _decode
function _decode(data: Buffer, encoding?: string): any {
let value = null;
let rest = null;
let firstByte = data[0];
if (firstByte === Delimeters.i) {
return decodeInteger(data);
}
else if (encodesDigit(firstByte)) {
return decodeString(data, encoding);
}
else if (firstByte === Delimeters.l) {
return decodeList(data, encoding);
}
else if (firstByte === Delimeters.d) {
return decodeDict(data, encoding);
}
else {
throw new Error(`Expected d, i, l or digit, got "${data.toString()}"`);
}
}
示例5: toCreationAddress
/**
* If the tx's `to` is to the creation address
*/
toCreationAddress(): boolean {
return this.to.toString('hex') === ''
}