mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
fix encoding blob as base64
This commit is contained in:
@@ -185,7 +185,7 @@ function encodeBlob(packet, supportsBinary, callback) {
|
||||
|
||||
exports.encodeBase64Packet = function(packet, callback) {
|
||||
var message = 'b' + exports.packets[packet.type];
|
||||
if (Blob && packet.data instanceof Blob) {
|
||||
if (Blob && packet.data instanceof global.Blob) {
|
||||
var fr = new FileReader();
|
||||
fr.onload = function() {
|
||||
var b64 = fr.result.split(',')[1];
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
var parser = require('../../lib/browser.js');
|
||||
var expect = require('expect.js');
|
||||
var Blob = require('blob');
|
||||
|
||||
/**
|
||||
* Shortcuts
|
||||
@@ -71,4 +72,21 @@ describe('parser', function() {
|
||||
fr.readAsArrayBuffer(data);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encode blob as base64', function(done) {
|
||||
var buf = new Uint8Array(5);
|
||||
for (var i = 0; i < buf.length; i++) buf[i] = i;
|
||||
|
||||
encode({ type: 'message', data: new Blob([buf.buffer]) }, false, function(data) {
|
||||
var packet = decode(data, 'blob');
|
||||
expect(packet.type).to.eql('message');
|
||||
expect(packet.data).to.be.a(global.Blob);
|
||||
var fr = new FileReader();
|
||||
fr.onload = function() {
|
||||
expect(new Uint8Array(fr.result)).to.eql(buf);
|
||||
done();
|
||||
};
|
||||
fr.readAsArrayBuffer(packet.data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user