mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
removed dechunker
This commit is contained in:
parent
8503ac8884
commit
6c62deeda9
@ -8,6 +8,7 @@
|
||||
"dependencies": {
|
||||
"web3-core-helpers": "^1.0.0",
|
||||
"underscore": "^1.8.3",
|
||||
"oboe": "^2.1.3",
|
||||
"xmlhttprequest": "*",
|
||||
"xhr2": "*"
|
||||
},
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
var _ = require('underscore');
|
||||
var errors = require('web3-core-helpers').errors;
|
||||
var oboe = require('oboe');
|
||||
|
||||
|
||||
var IpcProvider = function (path, net) {
|
||||
@ -38,11 +39,10 @@ var IpcProvider = function (path, net) {
|
||||
|
||||
|
||||
// LISTEN FOR CONNECTION RESPONSES
|
||||
this.connection.on('data', function(data) {
|
||||
oboe(this.connection)
|
||||
.done(function(result) {
|
||||
/*jshint maxcomplexity: 6 */
|
||||
|
||||
_this._parseResponse(data.toString()).forEach(function(result){
|
||||
|
||||
var id = null;
|
||||
|
||||
// get the id which matches the returned id
|
||||
@ -68,7 +68,6 @@ var IpcProvider = function (path, net) {
|
||||
delete _this.responseCallbacks[id];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -101,60 +100,6 @@ IpcProvider.prototype.addDefaultEvents = function(){
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
Will parse the response and make an array out of it.
|
||||
|
||||
@method _parseResponse
|
||||
@param {String} data
|
||||
*/
|
||||
IpcProvider.prototype._parseResponse = function(data) {
|
||||
var _this = this,
|
||||
returnValues = [];
|
||||
|
||||
// DE-CHUNKER
|
||||
var dechunkedData = data
|
||||
.replace(/\}[\n\r]?\{/g,'}|--|{') // }{
|
||||
.replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{
|
||||
.replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{
|
||||
.replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{
|
||||
.split('|--|');
|
||||
|
||||
dechunkedData.forEach(function(data){
|
||||
|
||||
// prepend the last chunk
|
||||
if(_this.lastChunk)
|
||||
data = _this.lastChunk + data;
|
||||
|
||||
var result = null;
|
||||
|
||||
try {
|
||||
result = JSON.parse(data);
|
||||
|
||||
} catch(e) {
|
||||
|
||||
_this.lastChunk = data;
|
||||
|
||||
// start timeout to cancel all requests
|
||||
clearTimeout(_this.lastChunkTimeout);
|
||||
_this.lastChunkTimeout = setTimeout(function(){
|
||||
_this._timeout();
|
||||
throw errors.InvalidResponse(data);
|
||||
}, 1000 * 15);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// cancel timeout and set chunk to null
|
||||
clearTimeout(_this.lastChunkTimeout);
|
||||
_this.lastChunk = null;
|
||||
|
||||
if(result)
|
||||
returnValues.push(result);
|
||||
});
|
||||
|
||||
return returnValues;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Get the adds a callback to the responseCallbacks object,
|
||||
|
Loading…
x
Reference in New Issue
Block a user