cameron-streams
Advanced tools
Comparing version 0.1.2 to 0.1.3
38
index.js
(function() { | ||
var EmitterStream, RandomStream, SlowStream, crypto, stream, | ||
var EmitterStream, RandomEncodedStream, RandomStream, SlowStream, crypto, stream, _ref, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -27,6 +27,10 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
RandomStream.prototype.generateRandomChunk = function(size) { | ||
return crypto.randomBytes(size); | ||
}; | ||
RandomStream.prototype._read = function(size) { | ||
size = Math.min(size, this.totalBytes - this.bytesRead); | ||
this.bytesRead += size; | ||
this.push(crypto.randomBytes(size)); | ||
this.push(this.generateRandomChunk(size)); | ||
if (this.bytesRead >= this.totalBytes) { | ||
@@ -42,2 +46,29 @@ return this.push(null); | ||
/* | ||
A readable stream that provides random encoded characters. The encoding used | ||
can be overriden by setting `instance.encoding`. | ||
Set the total size of the random bytes provided across all "readable" | ||
events with the `totalBytes` argument (see parent class). | ||
*/ | ||
RandomEncodedStream = (function(_super) { | ||
__extends(RandomEncodedStream, _super); | ||
function RandomEncodedStream() { | ||
_ref = RandomEncodedStream.__super__.constructor.apply(this, arguments); | ||
return _ref; | ||
} | ||
RandomEncodedStream.prototype.encoding = 'hex'; | ||
RandomEncodedStream.prototype.generateRandomChunk = function(size) { | ||
return RandomEncodedStream.__super__.generateRandomChunk.call(this, size).toString(this.encoding).slice(0, size); | ||
}; | ||
return RandomEncodedStream; | ||
})(RandomStream); | ||
/* | ||
A Writable stream that emits "write" events for every write. | ||
@@ -92,2 +123,5 @@ | ||
}, | ||
encoded: function(size, options) { | ||
return new RandomEncodedStream(size, options); | ||
}, | ||
emitter: function(options) { | ||
@@ -94,0 +128,0 @@ return new EmitterStream(options); |
{ | ||
"name": "cameron-streams", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Streams to help with testing other streams.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,1 +60,3 @@ # Cameron Streams | ||
``` | ||
You can also get a random stream of more readable output using `cameron.encoded()`. By default, the random bytes are hex encoded. |
Sorry, the diff of this file is not supported yet
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
13311
94
62