Skip to content

Instantly share code, notes, and snippets.

@flimshaw
Last active May 5, 2017
Embed
What would you like to do?
var http = require('http')
class HttpStore {
constructor(storeUrl) {
// begin downloading the url we requested, stream it to our handleData function
http.get(storeUrl, (res) => {
res.on('data', this.handleData.bind(this))
res.on('end', this.handleEnd.bind(this))
})
this.bytesIn = 0;
this.downloaded = 0;
this.chunkCounter = 0;
this.loading = true;
this.chunkSize = 16384;
this.queue = [];
}
handleData(buf) {
// queue the most recent packet of data for transmission to the GPU, pass some info about it
this.queue.push({
buf: buf,
offset: this.chunkCounter,
count: buf.length
})
// increment our packet counter
this.chunkCounter += buf.length;
}
handleEnd(data) {
console.log("DONE");
}
// called on enterframe, apply all queued updates to the particle simulation
update(view) {
this.queue.map( (q) => {
view.queueUpdate(q.buf, q.offset, q.count);
})
this.queue = [];
}
}
module.exports = HttpStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment