Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Stream(host, port, mode) { ... }
- Stream.new = function(host, port, mode) { return new Stream(host, port, mode); }
- Stream.prototype = Object.create(Object.prototype, {
- readable: { get: function() { ... },
- writable: true, enumerable: false, configurable: true },
- writable: { get: function() { ... },
- writable: true, enumerable: false, configurable: true },
- read: { value: function(callback) { ... },
- writable: true, enumerable: false, configurable: true },
- write: { value: function(data) { ... },
- writable: true, enumerable: false, configurable: true },
- pipe: { value: function(strm) {
- if ( ! (strm instanceof Stream))
- throw new TypeError('Stream.pipe must only be given a valid stream as its first parameter.')
- this.read(strm.write.bind(strm));
- }, writable: true, enumerable: false, configurable: true }
- });
- function MemoryStream(capacity) { ...
- Object.defineProperty(this, 'buffer', {
- value: new Buffer(capacity), configurable: true
- });
- }
- MemoryStream.new = function(cap) { return new MemoryStream(cap); }
- MemoryStream.prototype = Object.create(Stream.prototype, {
- capacity: { get: function() { return this.buffer.capacity } },
- size: { get: function() { return this.buffer.size } },
- buffer: { value: new Buffer(), configurable: true },
- readable: { get: function() { return this.size > 0 } },
- writable: { get: function() { return this.capacity > this.size } },
- read: { value: function() {
- return buffer.empty();
- }, writable: true, enumerable: false, configurable: true },
- write: { value: function(data) {
- buffer.push(data);
- }, writable: true, enumerable: false, configurable: true },
- }, writable: true, enumerable: false, configurable: true }
- );
- var strm = Stream.new('127.0.0.1', 8080),
- mstrm = MemoryStream.new(1024);
- mstrm.pipe(strm);
- mstrm.write('HelloWorld!');
Add Comment
Please, Sign In to add comment