forked from socketio/socket.io-parser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblob.js
67 lines (59 loc) · 1.53 KB
/
blob.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var parser = require('../index.js');
var expect = require('expect.js');
var helpers = require('./helpers.js');
var encode = parser.encode;
var decode = parser.decode;
var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder || global.MozBlobBuilder;
describe('parser', function() {
it('encodes a Blob', function() {
var data;
if (BlobBuilder) {
var bb = new BlobBuilder();
bb.append(new ArrayBuffer(2));
data = bb.getBlob();
} else {
data = new Blob([new ArrayBuffer(2)]);
}
var packet = {
type: parser.BINARY_EVENT,
data: data,
id: 0,
nsp: '/'
};
helpers.test_bin(packet);
});
it('encodes an Blob deep in JSON', function() {
var data;
if (BlobBuilder) {
var bb = new BlobBuilder();
bb.append(new ArrayBuffer(2));
data = bb.getBlob();
} else {
data = new Blob([new ArrayBuffer(2)]);
}
var packet = {
type: parser.BINARY_EVENT,
data: {a: 'hi', b: { why: data }, c: 'bye'},
id: 999,
nsp: '/deep'
};
helpers.test_bin(packet);
});
it('encodes a binary ack with a blob', function() {
var data;
if (BlobBuilder) {
var bb = new BlobBuilder();
bb.append(new ArrayBuffer(2));
data = bb.getBlob();
} else {
data = new Blob([new ArrayBuffer(2)]);
}
var packet = {
type: parser.BINARY_ACK,
data: {a: 'hi ack', b: { why: data }, c: 'bye ack'},
id: 999,
nsp: '/deep'
};
helpers.test_bin(packet);
})
});