UNPKG

tus-js-client-olalonde

Version:

A pure JavaScript client for the tus resumable upload protocol

25 lines (20 loc) 699 B
class FileSource { constructor(file) { this._file = file; this.size = file.size; } slice(start, end) { return this._file.slice(start, end); } close() {} } export 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"); }