MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / _removeBlobs

Function _removeBlobs

sdk/src/CloudSocketClientLib.js:6357–6390  ·  view source on GitHub ↗
(obj, curKey, containingObject)

Source from the content-addressed store, hash-verified

6355
6356 exports.removeBlobs = function(data, callback) {
6357 function _removeBlobs(obj, curKey, containingObject) {
6358 if (!obj)
6359 return obj;
6360
6361 // convert any blob
6362 if ((global.Blob && obj instanceof Blob) || (global.File && obj instanceof File)) {
6363 pendingBlobs++;
6364
6365 // async filereader
6366 var fileReader = new FileReader();
6367 fileReader.onload = function() { // this.result == arraybuffer
6368 if (containingObject) {
6369 containingObject[curKey] = this.result;
6370 } else {
6371 bloblessData = this.result;
6372 }
6373
6374 // if nothing pending its callback time
6375 if (!--pendingBlobs) {
6376 callback(bloblessData);
6377 }
6378 };
6379
6380 fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer
6381 } else if (isArray(obj)) { // handle array
6382 for (var i = 0; i < obj.length; i++) {
6383 _removeBlobs(obj[i], i, obj);
6384 }
6385 } else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
6386 for (var key in obj) {
6387 _removeBlobs(obj[key], key, obj);
6388 }
6389 }
6390 }
6391
6392 var pendingBlobs = 0;
6393 var bloblessData = data;

Callers 1

Calls 3

isArrayFunction · 0.85
callbackFunction · 0.70
isBufFunction · 0.70

Tested by

no test coverage detected