@react-frontend-developer/buffers
Version:
Helper utilities for manipulating Buffers and TypedArrays
46 lines (39 loc) • 2.04 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
import { Buffers } from './Buffers';
var TypedArrays = /*#__PURE__*/function () {
function TypedArrays() {
_classCallCheck(this, TypedArrays);
}
_createClass(TypedArrays, null, [{
key: "string2ab",
value: function string2ab(str) {
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
var buffer = Buffer.from(str, encoding);
return Buffers.copyToArrayBuffer(buffer);
}
}, {
key: "ab2string",
value: function ab2string(ab) {
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
return Buffer.from(ab).toString(encoding);
}
}, {
key: "string2Uint8Array",
value: function string2Uint8Array(str) {
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
var buffer = Buffer.from(str, encoding);
return Buffers.copyToUint8Array(buffer);
}
}, {
key: "uint8Array2string",
value: function uint8Array2string(arr) {
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
return Buffer.from(arr).toString(encoding);
}
}]);
return TypedArrays;
}();
export { TypedArrays };
//# sourceMappingURL=TypedArrays.js.map