Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should decode and decompress reading a byte buffer", () => {
// given
const base64 = require("base64-js");
const buffer = new ByteBuffer(
base64.toByteArray(
"HISTFAAAACB42pNpmSzMwMDAxAABMJqRQf4/GNh/gAgEMwEAkp4I6Q=="
)
);
// when
const histogram = AbstractHistogram.decodeFromCompressedByteBuffer(
buffer,
Int32Histogram,
0
);
// then
expect(histogram.getMean()).to.be.equal(42);
expect(histogram.getTotalCount()).to.be.equal(1);
});
export default function(str, encoding = 'utf-8') {
// decode
const bytes = base64js.toByteArray(str);
return new TextDecoder(encoding).decode(bytes);
}
const ServiceDecoration = (props: Props) => {
// Parse JSON to get the type of the decoration
let parsed: RPCChatTypes.UITextDecoration
try {
const json = Buffer.from(toByteArray(props.json)).toString()
parsed = JSON.parse(json)
} catch (e) {
return null
}
if (parsed.typ === RPCChatTypes.UITextDecorationTyp.payment && props.message) {
let paymentID: WalletTypes.PaymentID | undefined
let error
if (
parsed.payment.result.resultTyp === RPCChatTypes.TextPaymentResultTyp.sent &&
parsed.payment.result.sent
) {
paymentID = WalletTypes.rpcPaymentIDToPaymentID(parsed.payment.result.sent)
} else if (
parsed.payment.result.resultTyp === RPCChatTypes.TextPaymentResultTyp.error &&
parsed.payment.result.error
) {
DeviceEventEmitter.addListener(kCommandReceiveCallBackName, ({ command, data }) => {
console.log('reach serverCmd callback');
if (command == MISSCommand.MISS_CMD_SPEAKER_START_RESP) {
console.log(' receive start speaker');
console.log('data:' + data);
var ba = base64js.toByteArray(data);
if (ba.length > 0) {
console.log('receive start speaker 0');
console.log(ba[0]);
if (Platform.OS === 'android') {
if (ba[0] == 48) {
console.log("start call in android");
this.refs.openGLViewRef.startAudioRecord();
}
} else {
if (ba[0] == 0) {
this.refs.openGLViewRef.startAudioRecord();
}
}
}
} else {
console.log('receive command:' + command + ' data:' + JSON.stringify(data));
reader.addEventListener('loadend', () => {
const keyWordArray = CryptoJS.enc.Base64.parse(file.key);
const ivWordArray = CryptoJS.enc.Base64.parse(file.iv);
const content = CryptoJS.lib.WordArray.create(reader.result);
const encryptedWordArray = CryptoJS.AES.encrypt(content, keyWordArray, {
iv: ivWordArray
});
const encryptedBase64 = encryptedWordArray.toString();
const encryptedArrayBuffer = base64js.toByteArray(encryptedBase64);
callback(new Blob([new Uint8Array(encryptedArrayBuffer)]));
});
reader.readAsArrayBuffer(blob);
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
}
exports.init = function() {
var BrotliDecompressBuffer = require('./decode').BrotliDecompressBuffer;
var compressed = base64.toByteArray(require('./dictionary.bin.js'));
return BrotliDecompressBuffer(compressed);
};
if (this.readyState !== DONE) {
return null;
}
if (this._cachedResponse !== undefined) {
return this._cachedResponse;
}
switch (responseType) {
case 'document':
this._cachedResponse = null;
break;
case 'arraybuffer':
this._cachedResponse = base64.toByteArray(this._response).buffer;
break;
case 'blob':
if (typeof this._response === 'object' && this._response) {
this._cachedResponse = BlobManager.createFromOptions(this._response);
} else if (this._response === '') {
this._cachedResponse = null;
} else {
throw new Error(`Invalid response for blob: ${this._response}`);
}
break;
case 'json':
try {
this._cachedResponse = JSON.parse(this._response);
} catch (_) {
function base64ToBytes(str) {
return require("base64-js").toByteArray(str);
}
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
}