mirror of https://github.com/kern/filepizza
WIP
parent
c4b63ec0e3
commit
d8febe77be
@ -1,38 +1,46 @@
|
||||
import ChunkedBlob from './ChunkedBlob';
|
||||
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();
|
||||
this.name = name
|
||||
this.size = size
|
||||
this.type = type
|
||||
this.packets = new ChunkedBlob()
|
||||
}
|
||||
|
||||
addPacket(b) {
|
||||
this.packets.add(b);
|
||||
this.packets.add(b)
|
||||
}
|
||||
|
||||
clearPackets() {
|
||||
this.packets = new ChunkedBlob();
|
||||
this.packets = new ChunkedBlob()
|
||||
}
|
||||
|
||||
isComplete() {
|
||||
return this.packets.size === this.size;
|
||||
return this.getProgress() === 1
|
||||
}
|
||||
|
||||
getProgress() {
|
||||
return this.packets.size / this.size;
|
||||
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);
|
||||
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)
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
size: this.size,
|
||||
type: this.type
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,25 +1,33 @@
|
||||
const packetSize = 16 * 1024;
|
||||
const packetSize = 16 * 1024
|
||||
|
||||
export default class UploadFile {
|
||||
|
||||
constructor(file) {
|
||||
this.name = file.name;
|
||||
this.size = file.size;
|
||||
this.type = file.type;
|
||||
this.blob = file;
|
||||
this.name = file.name
|
||||
this.size = file.size
|
||||
this.type = file.type
|
||||
this.blob = file
|
||||
}
|
||||
|
||||
countPackets() {
|
||||
return Math.ceil(this.size / packetSize);
|
||||
return Math.ceil(this.size / packetSize)
|
||||
}
|
||||
|
||||
getPacket(i) {
|
||||
if (i < 0 || i >= this.countPackets())
|
||||
throw new Error('Packet out of bounds');
|
||||
throw new Error('Packet out of bounds')
|
||||
|
||||
let start = i * packetSize;
|
||||
let end = Math.min(start + packetSize, this.size);
|
||||
return this.blob.slice(start, end);
|
||||
let start = i * packetSize
|
||||
let end = Math.min(start + packetSize, this.size)
|
||||
return this.blob.slice(start, end)
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
size: this.size,
|
||||
type: this.type
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var Alt = require('alt');
|
||||
export default new Alt();
|
||||
import Alt from 'alt'
|
||||
export default new Alt()
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue