Removed output double boffering in deflate wrappermake test

This commit is contained in:
Vitaly Puzrin 2014-02-15 01:35:10 +04:00
parent 3288124672
commit c1383793f6

View file

@ -32,7 +32,6 @@ var Deflate = function(options) {
} }
this.strm = new zstream(); this.strm = new zstream();
this.strm.next_out = utils.arrayCreate(opt.chunkSize);
var status = zlib_deflate.deflateInit2( var status = zlib_deflate.deflateInit2(
this.strm, this.strm,
@ -53,11 +52,13 @@ var Deflate = function(options) {
*/ */
Deflate.prototype.push = function(data_in) { Deflate.prototype.push = function(data_in) {
var strm = this.strm; var strm = this.strm;
var out; var chunkSize = this.options.chunkSize;
var sliced;
strm.next_in = data_in; strm.next_in = data_in;
strm.next_in_index = 0; strm.next_in_index = 0;
strm.avail_in = strm.next_in.length; strm.avail_in = strm.next_in.length;
strm.next_out = utils.arrayCreate(chunkSize);
/* run deflate() on input until output buffer not full, finish /* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */ compression if all of source has been read in */
@ -71,9 +72,17 @@ Deflate.prototype.push = function(data_in) {
// this.onEnd(ret); // this.onEnd(ret);
//} //}
if(strm.next_out_index) { if(strm.next_out_index) {
out = utils.arrayCreate(strm.next_out_index); if (strm.next_out_index === chunkSize) {
utils.arraySet(out, strm.next_out, 0, strm.next_out_index, 0); // out buffer completely filled, push it as is
this.onData(out); this.onData(strm.next_out);
} else {
// out buffer partially filled, slice it first
sliced = utils.arrayCreate(strm.next_out_index);
utils.arraySet(sliced, strm.next_out, 0, strm.next_out_index, 0);
this.onData(sliced);
}
// Allocate buffer for next chunk
strm.next_out = utils.arrayCreate(this.options.chunkSize);
} }
} while (strm.avail_in > 0 || strm.avail_out === 0); } while (strm.avail_in > 0 || strm.avail_out === 0);
}; };