本文整理汇总了TypeScript中base64-js.toByteArray函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toByteArray函数的具体用法?TypeScript toByteArray怎么用?TypeScript toByteArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toByteArray函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Uint8Array
false, ['encrypt','decrypt']).then((dekKey: CryptoKey) => {
let dat: Uint8Array;
if (encrypt) {
// Encode the message string as a byte array
dat = textEncoder.encode(em.message);
// Generate a random IV for seeding AES-CBC
em.iv = new Uint8Array(16);
crypto.getRandomValues(em.iv);
// Encode the IV to be persisted later
em.ivB64 = b64.fromByteArray(em.iv);
}
else {
// Decode the IV
em.iv = b64.toByteArray(em.ivB64);
// Decode the encrypted message
em.messageEnc = b64.toByteArray(em.messageEncB64);
dat = em.messageEnc;
}
// Setup the encryptiong/decryption parameters
let encryptAlgor = {
name: 'AES-CBC',
iv: em.iv,
};
// Either encrypt or decrypt
if (encrypt) {
crypto.subtle.encrypt(encryptAlgor, dekKey, dat).then((crypt: ArrayBuffer) => {
em.messageEnc = new Uint8Array(crypt);
em.messageEncB64 = b64.fromByteArray(em.messageEnc);
if (fn != null) {
fn();
}
})
}
else {
crypto.subtle.decrypt(encryptAlgor, dekKey, dat).then((clear: ArrayBuffer) => {
em.message = textDecoder.decode(new Uint8Array(clear));
if (fn != null) {
fn();
}
})
}
});
示例2: loadConsumer
function loadConsumer(source: string): SourceMapConsumer {
let consumer = consumers.get(source);
if (consumer == null) {
const code = getGeneratedContents(source);
if (!code) {
return null;
}
let sourceMappingURL = retrieveSourceMapURL(code);
if (!sourceMappingURL) {
throw Error("No source map?");
}
let sourceMapData: string;
if (reSourceMap.test(sourceMappingURL)) {
// Support source map URL as a data url
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
const ui8 = base64.toByteArray(rawData);
sourceMapData = arrayToStr(ui8);
sourceMappingURL = source;
} else {
// Support source map URLs relative to the source URL
//sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
sourceMapData = getGeneratedContents(sourceMappingURL);
}
//console.log("sourceMapData", sourceMapData);
const rawSourceMap = JSON.parse(sourceMapData);
consumer = new SourceMapConsumer(rawSourceMap);
consumers.set(source, consumer);
}
return consumer;
}
示例3: inflate
export function inflate(input: string) {
if (!input) {
return input;
}
const bytes = base64.toByteArray(input);
const restored = toString(bytes);
return JSON.parse(restored);
}
示例4: unpack
function unpack(data: string): Uint32Array {
const binary = base64js.toByteArray(data);
const bits = binary[0];
const values = new Uint32Array((binary.length - 1) / bits);
for (let i = 1; i < binary.length; i += bits) {
// Values are written little-endian.
for (let j = bits - 1; j >= 0; j--) {
values[(i - 1) / bits] <<= 8;
values[(i - 1) / bits] |= binary[i + j] | 0;
}
}
return values;
}
示例5: decompressCode
function decompressCode(compressedCode: string): string {
return String.fromCharCode(...GZip.unzip(Base64.toByteArray(compressedCode)));
}
示例6:
import * as base64js from "base64-js";
const length: number = base64js.byteLength("");
const bytes: Uint8Array = base64js.toByteArray("");
const decoded: string = base64js.fromByteArray(new Uint8Array(0));
示例7: decryptMessage
static decryptMessage(em: EphemeralMessage, fn?:()=>any) {
em.mek = b64.toByteArray(em.mekB64);
em.salt = b64.toByteArray(em.saltB64);
return this.applyKey(em, false, fn);
}
示例8:
/// <reference path="base64-js.d.ts" />
import * as base64js from 'base64-js';
const bytes: Uint8Array = base64js.toByteArray('shemp');
const decoded: string = base64js.fromByteArray(new Uint8Array(0));
示例9:
import * as base64js from "base64-js";
base64js.byteLength(""); // $ExpectType number
base64js.toByteArray(""); // $ExpectType Uint8Array
base64js.fromByteArray(new Uint8Array(0)); // $ExpectTpe string
示例10: saveTypeCache
function saveTypeCache() {
const composedCache: ComposedCache = {}
for (const type in typeCache) {
composedCache[type] = {
sig: typeCache[type].sig,
type: base64.fromByteArray(new Uint8Array(typeCache[type].type.toBuffer()))
}
}
localStorage.typeCache = JSON.stringify(composedCache)
}
if (localStorage.typeCache) {
const composedCache: ComposedCache = JSON.parse(localStorage.typeCache)
for (const typeName in composedCache) {
typeCache[typeName] = {
sig: composedCache[typeName].sig,
type: r.type(base64.toByteArray(composedCache[typeName].type).buffer)
}
}
}
export interface DownloadOptions {
name: string
url: string
options?: RequestInit
}
export function download({name, url, options}: DownloadOptions): Promise<any> {
assert.instanceOf(name, String)
assert.instanceOf(url, String)
options = options || {}
assert.instanceOf(options, Object)
const typeInCache = typeCache[name]