tor-browser

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

is-buffer.js (1040B)


      1 /*
      2 * A socket.io encoder and decoder written in JavaScript complying with version 4
      3 * of socket.io-protocol. Used by socket.io and socket.io-client.
      4 *
      5 * Copyright (c) 2014 Guillermo Rauch <guillermo@learnboost.com>
      6 *
      7 * This source code is licensed under the MIT license found in the
      8 * LICENSE file in the root directory of the library source tree.
      9 *
     10 * https://github.com/socketio/socket.io-parser
     11 */
     12 
     13 /* eslint-disable no-undef */
     14 
     15 "use strict";
     16 
     17 var withNativeBuffer =
     18  typeof Buffer === "function" && typeof Buffer.isBuffer === "function";
     19 var withNativeArrayBuffer = typeof ArrayBuffer === "function";
     20 
     21 var isView = function (obj) {
     22  return typeof ArrayBuffer.isView === "function"
     23    ? ArrayBuffer.isView(obj)
     24    : obj.buffer instanceof ArrayBuffer;
     25 };
     26 
     27 /**
     28 * Returns true if obj is a buffer or an arraybuffer.
     29 *
     30 * @private
     31 */
     32 
     33 function isBuf(obj) {
     34  return (
     35    (withNativeBuffer && Buffer.isBuffer(obj)) ||
     36    (withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)))
     37  );
     38 }
     39 
     40 module.exports = isBuf;