better DataStream.prototype.end implementation