-
-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect header check with zlib header #256
Comments
Can this be a dupe of #174 (comment) (header set wrong window size)? |
🙏🏼 I'm not sure if this relates, but I try to serialize and de-serialize plain javascript objects to a compressed base64 url safe string and back, but got the same issues (using NextJS13). Using: // Dependencies
"@types/pako": "^2.0.0",
// AND Development dependencies
"next": "^13.1.1",
"pako": "^2.1.0", something like: 'use client';
import { deflate, inflate } from 'pako';
import { plainToInstance, instanceToPlain } from 'class-transformer';
import { encode, decode } from 'js-base64';
import { DTO } from './dto';
/**
* Serializes an object to compressed base64 string
*/
export function serializeState<A extends DTO>(appState: A) {
const plain = instanceToPlain(appState);
const jsonString = JSON.stringify(plain);
const compressed = deflate(jsonString);
const compressedString = new window.TextDecoder().decode(compressed)
return encode(compressedString, true);
}
/**
* De-Serializes compressed Base64 string to class instance
*/
export function deserializeState<A extends DTO>(
DTO: new (...args) => A,
appState: string
): A {
const compressedString = decode(appState);
const compressed = new window.TextEncoder().encode(compressedString)
const jsonString = inflate(compressed, {to : 'string'})
const plain = JSON.parse(jsonString);
return plainToInstance(EnkDTO, plain);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello all,
I think I've found a bug in decompressing this data file. (It's an old data file that I did not create, and I had to do a lot of digging and guessing to figure out what the hell it was.) It appears to have a 2-byte zlib header (78 DA). From my reading through the docs and the code, it seems that by default
pako.inflate()
should auto-detect whether there's a zlib header as opposed to a gzip header. However, I get an incorrect header check error when doingpako.inflate()
.The standard Python zlib library has no problems with it.
For my specific application, I think I can get away with removing the zlib header and using
pako.inflateRaw()
, but it seems likepako.inflate()
should be able to handle it.The text was updated successfully, but these errors were encountered: