Skip to content

Commit

Permalink
This just cleans up the code, probably no fix (#2066)
Browse files Browse the repository at this point in the history
* clean up todo_writing
  • Loading branch information
baudehlo authored and msimerson committed Sep 30, 2017
1 parent add5530 commit 13f715e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion outbound/hmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ HMailItem.prototype.read_todo = function () {
// I'm making the assumption here we won't ever read less than 4 bytes
// as no filesystem on the planet should be that dumb...
tl_reader.destroy();
const todo_len = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
const todo_len = buf.readUInt32BE(0);
const td_reader = fs.createReadStream(self.path, {encoding: 'utf8', start: 4, end: todo_len + 3});
self.data_start = todo_len + 4;
let todo = '';
Expand Down
17 changes: 6 additions & 11 deletions outbound/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,15 @@ exports.build_todo = function (todo, ws, write_more) {
return value;
}
}
const todo_str = new Buffer(JSON.stringify(todo, exclude_from_json));

// since JS has no pack() we have to manually write the bytes of a long
const todo_length = new Buffer(4);
const todo_l = todo_str.length;
todo_length[3] = todo_l & 0xff;
todo_length[2] = (todo_l >> 8) & 0xff;
todo_length[1] = (todo_l >> 16) & 0xff;
todo_length[0] = (todo_l >> 24) & 0xff;

const buf = Buffer.concat([todo_length, todo_str], todo_str.length + 4);
const todo_json = JSON.stringify(todo, exclude_from_json);
const buf = new Buffer(4 + todo_json.length);
buf.writeUInt32BE(todo_json.length, 0);
buf.write(todo_json, 4);

const continue_writing = ws.write(buf);
if (continue_writing) return write_more();
if (continue_writing) return process.nextTick(write_more);

ws.once('drain', write_more);
};

Expand Down

0 comments on commit 13f715e

Please sign in to comment.