How to use the base64-js.toByteArray function in base64-js

To help you get started, we’ve selected a few base64-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HdrHistogram / HdrHistogramJS / src / encoding.spec.ts View on Github external
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);
  });
github noironetworks / aci-containers / vendor / github.com / hashicorp / consul / ui-v2 / app / utils / atob.js View on Github external
export default function(str, encoding = 'utf-8') {
  // decode
  const bytes = base64js.toByteArray(str);
  return new TextDecoder(encoding).decode(bytes);
}
github keybase / client / shared / common-adapters / markdown / service-decoration.tsx View on Github external
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
    ) {
github MiEcosystem / miot-plugin-sdk / projects / com.xiaomi.camera.demo / MainPage.js View on Github external
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));
github Criptext / Criptext-Email-React-Client / email_composer / src / utils / FileUtils.js View on Github external
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);
github HBM / node-jet / build / jet.js View on Github external
function base64ToBytes (str) {
  return base64.toByteArray(base64clean(str))
}
github foliojs / brotli.js / dec / dictionary-browser.js View on Github external
exports.init = function() {
  var BrotliDecompressBuffer = require('./decode').BrotliDecompressBuffer;
  var compressed = base64.toByteArray(require('./dictionary.bin.js'));
  return BrotliDecompressBuffer(compressed);
};
github Marwan01 / food-converter / node_modules / react-native / Libraries / Network / XMLHttpRequest.js View on Github external
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 (_) {
github aldonline / reactivity / build / reactivity.js View on Github external
function base64ToBytes(str) {
  return require("base64-js").toByteArray(str);
}

base64-js

Base64 encoding/decoding in pure JS

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis