Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

gunzip.inflate uses output encoding as to calculate buffer size in GunzipInflate #6

Open
Woodya opened this Issue Jun 5, 2011 · 0 comments

Comments

Projects
None yet
1 participant

Woodya commented Jun 5, 2011

inflate will not work for gzipped utf8 data, at least not directly.

the provided encoding param is use to both byte convert the input and to encode the output.
compress.cc line 326.

I think it's a copy/paste error that it's used on the input (who gunzips utf8 data...?), because the DecodeWrite call that follows explicitly uses BINARY, which means the length is calculated with one encoding and then the data is written with another (BINARY).

it is currently possible to work around this by always using 'binary', and then on output data handing, doing this:
var inflated = gz.inflate(data, 'binary');
var b = Buffer(inflated.length);
b.write(inflated, 0, 'binary');
var utf = b.toString('utf8');

but this is a major pain, and pretty wasteful wrt memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment