(obj, curKey, containingObject)
| 3144 | |
| 3145 | exports.removeBlobs = function(data, callback) { |
| 3146 | function _removeBlobs(obj, curKey, containingObject) { |
| 3147 | if (!obj) return obj; |
| 3148 | |
| 3149 | // convert any blob |
| 3150 | if ((global.Blob && obj instanceof Blob) || |
| 3151 | (global.File && obj instanceof File)) { |
| 3152 | pendingBlobs++; |
| 3153 | |
| 3154 | // async filereader |
| 3155 | var fileReader = new FileReader(); |
| 3156 | fileReader.onload = function() { // this.result == arraybuffer |
| 3157 | if (containingObject) { |
| 3158 | containingObject[curKey] = this.result; |
| 3159 | } |
| 3160 | else { |
| 3161 | bloblessData = this.result; |
| 3162 | } |
| 3163 | |
| 3164 | // if nothing pending its callback time |
| 3165 | if(! --pendingBlobs) { |
| 3166 | callback(bloblessData); |
| 3167 | } |
| 3168 | }; |
| 3169 | |
| 3170 | fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer |
| 3171 | } else if (isArray(obj)) { // handle array |
| 3172 | for (var i = 0; i < obj.length; i++) { |
| 3173 | _removeBlobs(obj[i], i, obj); |
| 3174 | } |
| 3175 | } else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object |
| 3176 | for (var key in obj) { |
| 3177 | _removeBlobs(obj[key], key, obj); |
| 3178 | } |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | var pendingBlobs = 0; |
| 3183 | var bloblessData = data; |
no test coverage detected