memorystream
Advanced tools
Comparing version 0.0.5 to 0.1.0
47
index.js
@@ -46,2 +46,3 @@ var stream = require('stream'), | ||
this.bufoverflow = options.hasOwnProperty('bufoveflow') ? options.bufoveflow : null; | ||
this.frequence = options.hasOwnProperty('frequence') ? options.frequence : null; | ||
@@ -56,14 +57,39 @@ process.nextTick(function(){ | ||
MemoryStream.createReadStream = function(data, options) { | ||
options = options || {}; | ||
options.readable = true; | ||
options.writable = false; | ||
return new MemoryStream(data,options); | ||
}; | ||
MemoryStream.createWriteStream = function(data, options){ | ||
options = options || {}; | ||
options.readable = false; | ||
options.writable = true; | ||
return new MemoryStream(data,options); | ||
}; | ||
MemoryStream.prototype._next = function() { | ||
var self = this; | ||
function next(){ | ||
if( self.flush() && self.readable){ | ||
function dodo(){ | ||
if( self.flush() && self.readable){ | ||
process.nextTick(next); | ||
} | ||
} | ||
if(self.frequence){ | ||
setTimeout(dodo,self.frequence); | ||
}else{ | ||
dodo(); | ||
} | ||
} | ||
next(); | ||
if( ! this.paused){ | ||
next(); | ||
} | ||
}; | ||
MemoryStream.prototype.getAll = function() { | ||
MemoryStream.prototype.toString = MemoryStream.prototype.getAll = function() { | ||
var self = this; | ||
@@ -89,16 +115,15 @@ var ret = ''; | ||
MemoryStream.prototype.pipe = function(destination, options) { | ||
util.pump(this, destination); | ||
}; | ||
MemoryStream.prototype.pause = function() { | ||
this.paused = true; | ||
if(this.readable){ | ||
this.paused = true; | ||
} | ||
}; | ||
MemoryStream.prototype.resume = function() { | ||
if(this.readable){ | ||
this.paused = false; | ||
this.paused = false; | ||
this._next(); | ||
this._next(); | ||
} | ||
}; | ||
@@ -105,0 +130,0 @@ |
{ | ||
"name": "memorystream", | ||
"description": "This is lightweight memory stream module for node.js.", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"keywords": [ | ||
"memory", | ||
"test", | ||
"stream", | ||
@@ -11,2 +12,6 @@ "tools", | ||
], | ||
"devDependencies" : { | ||
"expresso" : ">=0.7.x", | ||
"jslint" : "*" | ||
}, | ||
"author": "Dmitry Nizovtsev (https://github.com/JSBizon)", | ||
@@ -21,3 +26,7 @@ "contributors": [ | ||
"homepage": "https://github.com/JSBizon/node-memorystream", | ||
"engines": { "node": ">= 0.3.0" } | ||
"engines": { "node": ">= 0.3.0" }, | ||
"licenses": [ { | ||
"type": "MIT", | ||
"url" : "http://github.com/JSBizon/node-memorystream/raw/master/LICENSE" | ||
} ] | ||
} |
@@ -62,3 +62,3 @@ # Introduction | ||
res.on('end',function(){ | ||
console.log(memStream.getAll()); | ||
console.log(memStream.toString()); | ||
}); | ||
@@ -65,0 +65,0 @@ }); |
@@ -15,5 +15,5 @@ var http = require('http'), | ||
res.on('end',function(){ | ||
console.log(memStream.getAll()); | ||
console.log(memStream.toString()); | ||
}); | ||
}); | ||
req.end(); |
@@ -86,3 +86,3 @@ var MemoryStream = require('../index.js'), | ||
memStream.setEncoding('utf8'); | ||
memStream.getAll().should.be.eql('data1data2'); | ||
memStream.toString().should.be.eql('data1data2'); | ||
}); | ||
@@ -163,3 +163,3 @@ }, | ||
"test destroy" : function(beforeExit){ | ||
"test MemoryStream destroy" : function(beforeExit){ | ||
var memStream = new MemoryStream('data1'); | ||
@@ -174,3 +174,3 @@ memStream.write('data2').should.be.true; | ||
"test destroySoon" : function(beforeExit){ | ||
"test MemoryStream destroySoon" : function(beforeExit){ | ||
var memStream = new MemoryStream('data1'); | ||
@@ -194,2 +194,52 @@ var data = ''; | ||
}, | ||
"test MemoryStream createReadStream" : function(beforeExit){ | ||
var done = false; | ||
var memStream = MemoryStream.createReadStream(['hello',' ','world']); | ||
var data = ''; | ||
memStream.on('data', function(chunk){ | ||
data += chunk; | ||
}); | ||
memStream.on('end', function(){ | ||
data.should.equal('hello world'); | ||
done = true; | ||
}); | ||
beforeExit(function(){ | ||
done.should.be.true; | ||
}); | ||
}, | ||
"test MemoryStream createWriteStream" : function(beforeExit){ | ||
var memStream = MemoryStream.createWriteStream(); | ||
memStream.write('hello'); | ||
memStream.write(' '); | ||
memStream.write('world'); | ||
memStream.end(); | ||
memStream.toString().should.equal('hello world'); | ||
}, | ||
"test MemoryStream frequence" : function(beforeExit){ | ||
var memStream = MemoryStream.createReadStream(['hello',' ','world'],{frequence : 500}); | ||
var last = Date.now(); | ||
var done = false; | ||
var data = ''; | ||
memStream.on('data',function(chunk){ | ||
var now = Date.now(); | ||
((now - last) > 400).should.be.ok; | ||
last = now; | ||
data += chunk; | ||
}); | ||
memStream.on('end', function(){ | ||
done = true; | ||
}); | ||
beforeExit(function(){ | ||
done.should.be.true; | ||
}); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
15321
8
0
413
1
2