tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NetworkDataBytes.sys.mjs (1097B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 export class NetworkDataBytes {
      6  #getBytesValue;
      7  #isBase64;
      8 
      9  /**
     10   * Common interface used to handle network BytesValue for collected data which
     11   * might be encoded and require an additional async step in order to retrieve
     12   * the actual bytes.
     13   *
     14   * This is a simple wrapper mostly designed to ensure a common interface in
     15   * case this is used for request or response bodies.
     16   *
     17   * @param {object} options
     18   * @param {Function} options.getBytesValue
     19   *     A -potentially async- callable which returns the bytes as a string.
     20   * @param {boolean} options.isBase64
     21   *     Whether this represents a base64-encoded binary data.
     22   */
     23  constructor(options) {
     24    this.#getBytesValue = options.getBytesValue;
     25    this.#isBase64 = options.isBase64;
     26  }
     27 
     28  get isBase64() {
     29    return this.#isBase64;
     30  }
     31 
     32  async getBytesValue() {
     33    return this.#getBytesValue();
     34  }
     35 }