Skip to content
This repository was archived by the owner on Dec 1, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/js/chat/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
*/
nextChunk: function() {
var blob = this.file.slice(this.seek, this.seek + this.options.chunkSize);
this.reader.readAsArrayBuffer(blob);
this.reader.readAsBinaryString(blob);
},

/**
Expand Down Expand Up @@ -449,7 +449,7 @@
_onChunk: function(event) {
var data = event.target.result;

this.seek += data.byteLength;
this.seek += data.length;
this.trigger("chunk", this.id, data);

if (this.isDone())
Expand Down
19 changes: 4 additions & 15 deletions test/frontend/chat/filetransfermodel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,13 @@ describe("FileTransfer Model", function() {
function(done) {
var nbCalls = 1;
transfer.on("chunk", function(id, chunk) {
var view = new Uint8Array(chunk);
var c = String.fromCharCode.apply(null, view);

expect(id).to.not.be.Null;

if (nbCalls === 1) {
expect(c).to.equal('c');
expect(chunk).to.equal('c');
transfer.nextChunk();
}

if (nbCalls === 2) {
expect(c).to.equal('o');
expect(chunk).to.equal('o');
done();
}

Expand All @@ -100,10 +95,7 @@ describe("FileTransfer Model", function() {
it("should accepts a custom chunkSize", function(done) {
var chunks = [];
transfer.on("chunk", function(id, chunk) {
var view = new Uint8Array(chunk);
var str = String.fromCharCode.apply(null, view);

chunks.push(str);
chunks.push(chunk);
if (!transfer.isDone())
transfer.nextChunk();
});
Expand All @@ -119,10 +111,7 @@ describe("FileTransfer Model", function() {
it("should call complete when there are no chunks left", function(done) {
var chunks = [];
transfer.on("chunk", function(id, chunk) {
var view = new Uint8Array(chunk);
var str = String.fromCharCode.apply(null, view);

chunks.push(str);
chunks.push(chunk);
if (!transfer.isDone())
transfer.nextChunk();
});
Expand Down