Skip to content

Commit a58ed04

Browse files
committed
Fix to gzip behavior on short files (<1MB).
1 parent 28a4bfc commit a58ed04

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

trace/trace_server.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,11 @@ define(function(require){
402402
var buf = []
403403
var total = 0
404404

405-
function flush(){
405+
function flush(end){
406406
if(buf.length){
407407
gz.write(buf.join(''))
408+
gz.flush();
409+
if (end) gz.end();
408410
buf = []
409411
total = 0
410412
}
@@ -427,18 +429,18 @@ define(function(require){
427429

428430
process.on('exit', function(){
429431
console.log('exit!')
430-
//gz.end()
431432
})
432433

433434

434435
return function(m){
435-
if(!terminated){
436-
// we should buffer atleast a megabyte
437-
var data = '\x1f'+JSON.stringify(m)+'\x17'
438-
buf.push(data)
439-
total += data.length
440-
if(total > 1024*1024) flush()
441-
}
436+
if (!m) flush(true);
437+
else {
438+
// we should buffer atleast a megabyte
439+
var data = '\x1f'+JSON.stringify(m)+'\x17'
440+
buf.push(data)
441+
total += data.length
442+
if(total > 1024*1024) flush()
443+
}
442444
}
443445
}
444446

@@ -526,6 +528,10 @@ define(function(require){
526528
child.on('message', function(m){
527529
sender(m)
528530
})
531+
532+
child.on('exit', function () {
533+
sender(false);
534+
})
529535
}
530536

531537
function proxyMode(filter, port, bind, proxy, sender){

tracegl.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ define('/trace/trace_server',function(require){
403403
var buf = []
404404
var total = 0
405405

406-
function flush(){
406+
function flush(end){
407407
if(buf.length){
408408
gz.write(buf.join(''))
409+
gz.flush();
410+
if (end) gz.end();
409411
buf = []
410412
total = 0
411413
}
@@ -428,18 +430,18 @@ define('/trace/trace_server',function(require){
428430

429431
process.on('exit', function(){
430432
console.log('exit!')
431-
//gz.end()
432433
})
433434

434435

435436
return function(m){
436-
if(!terminated){
437-
// we should buffer atleast a megabyte
438-
var data = '\x1f'+JSON.stringify(m)+'\x17'
439-
buf.push(data)
440-
total += data.length
441-
if(total > 1024*1024) flush()
442-
}
437+
if (!m) flush(true);
438+
else {
439+
// we should buffer atleast a megabyte
440+
var data = '\x1f'+JSON.stringify(m)+'\x17'
441+
buf.push(data)
442+
total += data.length
443+
if(total > 1024*1024) flush()
444+
}
443445
}
444446
}
445447

@@ -527,6 +529,10 @@ define('/trace/trace_server',function(require){
527529
child.on('message', function(m){
528530
sender(m)
529531
})
532+
533+
child.on('exit', function () {
534+
sender(false);
535+
})
530536
}
531537

532538
function proxyMode(filter, port, bind, proxy, sender){

0 commit comments

Comments
 (0)