@@ -9,8 +9,6 @@ var isBuf = require('./is-buffer');
9
9
10
10
/**
11
11
* 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.
14
12
*
15
13
* @param {Object } packet - socket.io event packet
16
14
* @return {Object } with deconstructed packet and list of buffers
@@ -82,57 +80,3 @@ function _reconstructPacket(data, buffers) {
82
80
return data ;
83
81
}
84
82
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
- } ;
0 commit comments