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