Skip to content

Commit 46bfa8b

Browse files
author
Tom Atkinson
committed
Drop removeBlobs - not needed
1 parent a699d2d commit 46bfa8b

File tree

2 files changed

+5
-65
lines changed

2 files changed

+5
-65
lines changed

binary.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ var isBuf = require('./is-buffer');
99

1010
/**
1111
* Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder.
12-
* Anything with blobs or files should be fed through removeBlobs before coming
13-
* here.
1412
*
1513
* @param {Object} packet - socket.io event packet
1614
* @return {Object} with deconstructed packet and list of buffers
@@ -82,57 +80,3 @@ function _reconstructPacket(data, buffers) {
8280
return data;
8381
}
8482

85-
/**
86-
* Asynchronously removes Blobs or Files from data via
87-
* FileReader's readAsArrayBuffer method. Used before encoding
88-
* data as msgpack. Calls callback with the blobless data.
89-
*
90-
* @param {Object} data
91-
* @param {Function} callback
92-
* @api private
93-
*/
94-
95-
exports.removeBlobs = function(data, callback) {
96-
function _removeBlobs(obj, curKey, containingObject) {
97-
if (!obj) return obj;
98-
99-
// convert any blob
100-
if ((global.Blob && obj instanceof Blob) ||
101-
(global.File && obj instanceof File)) {
102-
pendingBlobs++;
103-
104-
// async filereader
105-
var fileReader = new FileReader();
106-
fileReader.onload = function() { // this.result == arraybuffer
107-
if (containingObject) {
108-
containingObject[curKey] = this.result;
109-
}
110-
else {
111-
bloblessData = this.result;
112-
}
113-
114-
// if nothing pending its callback time
115-
if(! --pendingBlobs) {
116-
callback(bloblessData);
117-
}
118-
};
119-
120-
fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer
121-
} else if (isArray(obj)) { // handle array
122-
for (var i = 0; i < obj.length; i++) {
123-
_removeBlobs(obj[i], i, obj);
124-
}
125-
} else if (typeof obj === 'object' && !isBuf(obj)) { // and object
126-
for (var key in obj) {
127-
_removeBlobs(obj[key], key, obj);
128-
}
129-
}
130-
}
131-
132-
var pendingBlobs = 0;
133-
var bloblessData = data;
134-
_removeBlobs(bloblessData);
135-
if (!pendingBlobs) {
136-
callback(bloblessData);
137-
}
138-
};

index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,12 @@ function encodeAsString(obj) {
184184

185185
function encodeAsBinary(obj, callback) {
186186

187-
function writeEncoding(bloblessData) {
188-
var deconstruction = binary.deconstructPacket(bloblessData);
189-
var pack = encodeAsString(deconstruction.packet);
190-
var buffers = deconstruction.buffers;
187+
var deconstruction = binary.deconstructPacket(obj);
188+
var pack = encodeAsString(deconstruction.packet);
189+
var buffers = deconstruction.buffers;
191190

192-
buffers.unshift(pack); // add packet info to beginning of data list
193-
callback(buffers); // write all the buffers
194-
}
195-
196-
binary.removeBlobs(obj, writeEncoding);
191+
buffers.unshift(pack); // add packet info to beginning of data list
192+
callback(buffers); // write all the buffers
197193
}
198194

199195
/**

0 commit comments

Comments
 (0)