UNPKG

@rpldy/chunked-sender

Version:

adds chunked upload capabilities on top of the regular XHR uploads

21 lines 785 B
import { merge, hasWindow } from "@rpldy/shared"; import { DEFAULT_OPTIONS } from "./defaults"; const getMandatoryOptions = options => merge({}, DEFAULT_OPTIONS, options); let sliceMethod = null; const isChunkingSupported = () => { sliceMethod = null; if (hasWindow() && "Blob" in window) { sliceMethod = Blob.prototype.slice || Blob.prototype.webkitSlice || Blob.prototype.mozSlice; } return !!sliceMethod; }; const 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; }; export { CHUNKING_SUPPORT, getMandatoryOptions, getChunkDataFromFile, isChunkingSupported };