Skip to content

Commit

Permalink
skip based on line number, not tile.x for deserialize streams
Browse files Browse the repository at this point in the history
  • Loading branch information
rclark committed Oct 2, 2014
1 parent ef301a6 commit 1a95e99
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/stream-deserialize.js
Expand Up @@ -19,6 +19,7 @@ function Deserialize(options) {
this._buffer = '';
this._decoder = new StringDecoder('utf8');
this._job = options.job || false;
this._linenum = 0;
}

Deserialize.prototype._transform = function(chunk, enc, callback) {
Expand All @@ -32,12 +33,13 @@ Deserialize.prototype._transform = function(chunk, enc, callback) {

if (line.toString() === serialHeader) continue;

this._linenum++;
if (this._job && this._linenum % this._job.total !== this._job.num - 1)
continue;

try { obj = deserialize(line); }
catch (err) { return callback(err); }

if (this._job && obj.x % this._job.total !== this._job.num - 1)
continue;

if (obj instanceof Info) this.emit('info', obj);
if (obj instanceof Tile) this.emit('tile', obj);
this.push(obj);
Expand All @@ -49,14 +51,15 @@ Deserialize.prototype._transform = function(chunk, enc, callback) {
Deserialize.prototype._flush = function(callback) {
var leftover = this._buffer.trim();
if (leftover) {
this._linenum++;
if (this._job && this._linenum % this._job.total !== this._job.num - 1)
return callback();

var obj;

try { obj = deserialize(leftover); }
catch (err) { return callback(err); }

if (this._job && obj.x % this._job.total !== this._job.num - 1)
return callback();

if (obj instanceof Info) this.emit('info', obj);
if (obj instanceof Tile) this.emit('tile', obj);
this.push(obj);
Expand Down

0 comments on commit 1a95e99

Please sign in to comment.