I'm getting some sort of encoded data from server, which should be properly decoded and displayed on client as string(UTF-16). By the moment I'm doing something like this:
_decodeContent: function(encodedContent) {
var binaryContent = atob(encodedContent);
var result = pako.inflate(binaryContent, { to: 'string' });
return result;
}
In most cases it works fine. But sometimes client have to handle massive amount data, so it freezes(Google Chrome 51.0.2704.84) or even crashes(Chromium 50.0.2661.102) browser tab. So I've find out, that problems is { to: 'string' } option in pako's inflate method, while trying to convert Uint8Array containing about 50kk elements to UTF-16 string.
I've tried to convert this manualy in a way like this:
_decodeContent: function(encodedContent) {
var binaryContent = atob(encodedContent);
var utf8 = pako.inflate(binaryContent);
var result = String.fromCharCode.apply(null, utf8);
return result;
}
But it produces: Uncaught RangeError: Maximum call stack size exceeded
So now I'm looking for solution to make things work faster, or at least prevent browsers from crashing. Any ideas?
UPD: Tried to do String.fromCharCode.apply
with chunks to prevent the exception. So problem with the exception was solved, but it works about two times slower than very first solution.
UPD: So the problem is how to convert massive Uint8Array to UTF-16 string preventing browser from freezing.