Give forward plugin its own folder. Should make it easier to clean it up.

This commit is contained in:
Simo Kinnunen
2014-10-14 16:24:18 +09:00
parent 035acec372
commit 100280db5a
3 changed files with 65 additions and 59 deletions

View File

@@ -0,0 +1,45 @@
var util = require('util')
var stream = require('stream')
var HEADER_SIZE = 4
var MAX_PACKET_SIZE = 0xFFFF
function ForwardWriter(target) {
stream.Transform.call(this)
this._target = target
}
util.inherits(ForwardWriter, stream.Transform)
ForwardWriter.prototype._transform = function(chunk, encoding, done) {
var header
, length
do {
length = Math.min(MAX_PACKET_SIZE, chunk.length)
header = new Buffer(HEADER_SIZE)
header.writeUInt16LE(this._target, 0)
header.writeUInt16LE(length, 2)
this.push(header)
this.push(chunk.slice(0, length))
chunk = chunk.slice(length)
}
while (chunk.length)
done()
}
ForwardWriter.prototype._flush = function(done) {
var header = new Buffer(HEADER_SIZE)
header.writeUInt16LE(this._target, 0)
header.writeUInt16LE(0, 2)
this.push(header)
done()
}
module.exports = ForwardWriter