Friday 9 July 2021

Unable to inflate SessionStorage data; getting either 'incorrect header check' or 'invalid stored block lengths' depending on the inflation method

I have data exceeding 5MB I need to store in session storage. To that end, I'm using pako to compress the data.

First, we have an Angular app that receives data from an API and adds it to a hash 'cachedLookups':

const stringifiedLookups = JSON.stringify(this.cachedLookups)
const compressedLookups = new TextDecoder().decode(pako.deflate(stringifiedLookups));
sessionStorage.setItem(this.sessionStorageKey, compressedLookups);

Then we have an AngularJS app in the same browser window that retrieves this data from the Session Storage:

const compressedLookups = localStorageService.get("cachedLookups");
const compressedLookupsUint8Array = new TextEncoder().encode(compressedLookups);
const stringifiedLookups = pako.inflate(compressedLookupsUint8Array, { to: 'string' });

When I hit pako.inflate, I get 'incorrect header check'. I've also tried inflateRaw, in which case I get 'invalid stored block lengths'. I'm using TextEncoder/Decoder here as attempting to store the Uint8Array directly into SessionStorage would force SessionStorage to exceed its quota, despite being calculated at under 5MB. I assume that issue had to do with the fact that the Storage API is all about storing key value string pairs.



from Unable to inflate SessionStorage data; getting either 'incorrect header check' or 'invalid stored block lengths' depending on the inflation method

No comments:

Post a Comment