@rpldy/chunked-sender
Version:
adds chunked upload capabilities on top of the regular XHR uploads
29 lines (28 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isChunkingSupported = exports.getMandatoryOptions = exports.getChunkDataFromFile = exports.CHUNKING_SUPPORT = void 0;
var _shared = require("@rpldy/shared");
var _defaults = require("./defaults");
const getMandatoryOptions = options => (0, _shared.merge)({}, _defaults.DEFAULT_OPTIONS, options);
exports.getMandatoryOptions = getMandatoryOptions;
let sliceMethod = null;
const isChunkingSupported = () => {
sliceMethod = null;
if ((0, _shared.hasWindow)() && "Blob" in window) {
sliceMethod = Blob.prototype.slice || Blob.prototype.webkitSlice || Blob.prototype.mozSlice;
}
return !!sliceMethod;
};
exports.isChunkingSupported = isChunkingSupported;
const CHUNKING_SUPPORT = exports.CHUNKING_SUPPORT = isChunkingSupported();
const getChunkDataFromFile = (file, start, end) => {
const blob = sliceMethod?.call(file, start, end, file.type);
if (blob) {
blob.name = file.name;
blob.lastModified = file.lastModified;
}
return blob;
};
exports.getChunkDataFromFile = getChunkDataFromFile;