mirror of https://github.com/kern/filepizza
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
695 B
JavaScript
39 lines
695 B
JavaScript
import ChunkedBlob from './ChunkedBlob';
|
|
|
|
export default class DownloadFile {
|
|
|
|
constructor(name, size, type) {
|
|
this.name = name;
|
|
this.size = size;
|
|
this.type = type;
|
|
this.packets = new ChunkedBlob();
|
|
}
|
|
|
|
addPacket(b) {
|
|
this.packets.add(b);
|
|
}
|
|
|
|
clearPackets() {
|
|
this.packets = new ChunkedBlob();
|
|
}
|
|
|
|
isComplete() {
|
|
return this.packets.size === this.size;
|
|
}
|
|
|
|
getProgress() {
|
|
return this.packets.size / this.size;
|
|
}
|
|
|
|
download() {
|
|
let blob = this.packets.toBlob();
|
|
let url = URL.createObjectURL(blob);
|
|
let a = document.createElement('a');
|
|
a.download = this.name;
|
|
a.href = url;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
}
|