Change gzip header extra to native array for convenience

master
Vitaly Puzrin 2014-04-18 09:30:59 +04:00
rodzic de4c26e3c8
commit d71a712e68
3 zmienionych plików z 15 dodań i 12 usunięć

Wyświetl plik

@ -38,9 +38,7 @@ exports.shrinkBuf = function (buf, size) {
var fnTyped = {
arraySet: function (dest, src, src_offs, len, dest_offs) {
// Suppose, that with typed array support destination is
// always typed - don't check it
if (src.subarray) {
if (src.subarray && dest.subarray) {
dest.set(src.subarray(src_offs, src_offs+len), dest_offs);
return;
}

Wyświetl plik

@ -13,21 +13,24 @@ function GZheader() {
/* pointer to extra field or Z_NULL if none */
this.extra = null;
/* extra field length (valid if extra != Z_NULL) */
this.extra_len = 0;
this.extra_len = 0; // Actually, we don't need it in JS,
// but leave for few code modifications
/* setup limits is not necessary because in js we should not preallocate memory */
/* for inflate use constant limit in 65536 bytes */
//
// Setup limits is not necessary because in js we should not preallocate memory
// for inflate use constant limit in 65536 bytes
//
/* space at extra (only when reading header) */
/*this.extra_max = 0;*/
// this.extra_max = 0;
/* pointer to zero-terminated file name or Z_NULL */
this.name = '';
/* space at name (only when reading header) */
/*this.name_max = 0;*/
// this.name_max = 0;
/* pointer to zero-terminated comment or Z_NULL */
this.comment = '';
/* space at comment (only when reading header) */
/*this.comm_max = 0;*/
// this.comm_max = 0;
/* true if there was or will be a header crc */
this.hcrc = 0;
/* true when done reading gzip header (not used when writing a gzip file) */

Wyświetl plik

@ -603,14 +603,16 @@ function inflate(strm, flush) {
if (state.head) {
len = state.head.extra_len - state.length;
if (!state.head.extra) {
state.head.extra = new utils.Buf8(state.head.extra_len);
// Use untyped array for more conveniend processing later
state.head.extra = new Array(state.head.extra_len);
}
utils.arraySet(
state.head.extra,
input,
next,
/* use constant limit because of extra field limitation in 65536 bytes */
len + copy > 65536 - len ? 65536 : copy,
// extra field is limited to 65536 bytes
// - no need for additional size check
copy,
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
len
);