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.
filepizza/client/ChunkedBlob.js

32 lines
495 B
JavaScript

export default class ChunkedBlob {
constructor(n) {
this.n = n;
this.count = n;
this.chunks = [];
}
setChunk(i, b) {
if (i < 0 || i >= this.n)
throw new Error('Chunk out of range');
if (this.chunks[i])
throw new Error('Chunk already set');
this.count--;
this.chunks[i] = b;
}
ready() {
return this.count === 0;
}
toBlob() {
if (!this.ready())
throw new Error('Incomplete blob');
return new Blob(this.chunks);
}
}