UNPKG

tus-js-client-olalonde

Version:

A pure JavaScript client for the tus resumable upload protocol

44 lines (34 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); exports.getSource = getSource; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var FileSource = function () { function FileSource(file) { _classCallCheck(this, FileSource); this._file = file; this.size = file.size; } _createClass(FileSource, [{ key: "slice", value: function slice(start, end) { return this._file.slice(start, end); } }, { key: "close", value: function close() {} }]); return FileSource; }(); function getSource(input) { // Since we emulate the Blob type in our tests (not all target browsers // support it), we cannot use `instanceof` for testing whether the input value // can be handled. Instead, we simply check is the slice() function and the // size property are available. if (typeof input.slice === "function" && typeof input.size !== "undefined") { return new FileSource(input); } throw new Error("source object may only be an instance of File or Blob in this environment"); }