@webex/http-core
Version:
Core HTTP library for the Cisco Webex
61 lines (59 loc) • 2.12 kB
JavaScript
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
_Object$defineProperty(exports, "__esModule", {
value: true
});
exports.default = detect;
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
var _fileType = require("file-type");
/*!
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
*/
/**
* Determine mimeType for the specified buffer;
* @param {Buffer|Uint8Array|ArrayBuffer} buffer
* @returns {Promise<string>}
*/
function detect(_x) {
return _detect.apply(this, arguments);
}
function _detect() {
_detect = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(buffer) {
var fileType;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!(!(buffer instanceof Blob) && !(buffer instanceof ArrayBuffer) && !(buffer instanceof Uint8Array))) {
_context.next = 2;
break;
}
throw new Error('`detect` requires a buffer of type Blob, ArrayBuffer, or Uint8Array');
case 2:
if (!(buffer instanceof Blob)) {
_context.next = 4;
break;
}
return _context.abrupt("return", buffer.type);
case 4:
_context.next = 6;
return (0, _fileType.fromBuffer)(buffer);
case 6:
fileType = _context.sent;
if (fileType) {
_context.next = 9;
break;
}
return _context.abrupt("return", 'application/octet-stream');
case 9:
return _context.abrupt("return", fileType.mime);
case 10:
case "end":
return _context.stop();
}
}, _callee);
}));
return _detect.apply(this, arguments);
}
//# sourceMappingURL=detect.js.map
;