本文整理汇总了TypeScript中text-encoding.TextDecoder类的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDecoder类的具体用法?TypeScript TextDecoder怎么用?TypeScript TextDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextDecoder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test_decoder
function test_decoder() {
var text = "plain text";
var uint8array: Uint8Array = TextEncoder().encode(text);
var arrayBuffer: ArrayBuffer = uint8array.buffer;
// constructor
text = new TextDecoder().decode(uint8array);
text = new TextDecoder("utf-8").decode(uint8array);
text = new TextDecoder("windows-1252", {}).decode(uint8array);
text = new TextDecoder("windows-1252", { fatal: true }).decode(uint8array);
text = new TextDecoder("windows-1252", { ignoreBOM: true }).decode(
uint8array
);
text = TextDecoder().decode(uint8array);
text = TextDecoder("utf-8").decode(uint8array);
text = TextDecoder("windows-1252", {}).decode(uint8array);
text = TextDecoder("windows-1252", { fatal: true }).decode(uint8array);
text = TextDecoder("windows-1252", { ignoreBOM: true }).decode(uint8array);
// attributes
var decoder = new TextDecoder();
var encoding: string = decoder.encoding;
var fatal: boolean = decoder.fatal;
var ignoreBOM: boolean = decoder.ignoreBOM;
// methods
decoder.decode();
decoder.decode(uint8array);
decoder.decode(arrayBuffer);
decoder.decode(uint8array, { stream: true });
}
示例2: reject
(err, paypro) => {
if (!disableLoader) this.onGoingProcessProvider.clear();
if (_.isArrayBuffer(err)) {
const enc = new encoding.TextDecoder();
err = enc.decode(err);
return reject(err);
} else if (err)
return reject(
this.translate.instant(
'Could Not Fetch Payment: Check if it is still valid'
)
);
else if (!paypro.verified) {
this.logger.warn('Failed to verify payment protocol signatures');
return reject(this.translate.instant('Payment Protocol Invalid'));
}
return resolve(paypro);
}
示例3: decode
export function decode(binary : Uint8Array, start = 0, end = binary.length) {
if(start !== 0 || end !== binary.length){
return decoder.decode(binary.subarray(start, end));
}else{
return decoder.decode(binary);
}
}
示例4: fn
crypto.subtle.decrypt(encryptAlgor, dekKey, dat).then((clear: ArrayBuffer) => {
em.message = textDecoder.decode(new Uint8Array(clear));
if (fn != null) {
fn();
}
})