stringstream
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "stringstream", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Encode and decode streams into string streams", | ||
@@ -5,0 +5,0 @@ "main": "stringstream.js", |
@@ -8,3 +8,3 @@ # Decode streams into strings The Right Way(tm) | ||
var stream = fs.createReadStream('massiveLogFile.gz') | ||
var utf8Stream = fs.createReadStream('massiveLogFile.gz') | ||
.pipe(zlib.createGunzip()) | ||
@@ -20,3 +20,3 @@ .pipe(strs('utf8')) | ||
```javascript | ||
// Stream from utf8 to hex to base64... Why not ay. | ||
// Stream from utf8 to hex to base64... Why not, ay. | ||
fs.createReadStream('myFile').pipe(strs('utf8', 'hex')).pipe(strs('hex', 'base64')) | ||
@@ -29,3 +29,3 @@ ``` | ||
```javascript | ||
var stream = fs.createReadStream('massiveLogFile.gz').pipe(strs('base64')) | ||
var stream = fs.createReadStream('myHugeFile').pipe(strs('base64')) | ||
@@ -36,4 +36,4 @@ var fileStr = '' | ||
stream.on('end', function() { | ||
console.log('My base64 encoded file is: ' + fileStr) | ||
console.log('My base64 encoded file is: ' + fileStr) // Wouldn't work with setEncoding() | ||
}) | ||
``` |
@@ -14,4 +14,4 @@ var util = require('util') | ||
this.readable = true | ||
this.writable = true | ||
this.readable = this.writable = true | ||
this.paused = false | ||
this.toEncoding = (typeof to === 'undefined' ? from : to) | ||
@@ -30,11 +30,33 @@ this.fromEncoding = (typeof to === 'undefined' ? '' : from) | ||
if (string.length) this.emit('data', string) | ||
return !this.paused | ||
} | ||
StringStream.prototype.end = function() { | ||
StringStream.prototype.flush = function() { | ||
var string = this.decoder.flush() | ||
if (string.length) this.emit('data', string) | ||
} | ||
StringStream.prototype.end = function() { | ||
if (!this.writable && !this.readable) return | ||
this.flush() | ||
this.emit('end') | ||
this.writable = this.readable = false | ||
this.destroy() | ||
} | ||
StringStream.prototype.destroy = function() { | ||
this.decoder = null | ||
this.writable = this.readable = false | ||
this.emit('close') | ||
} | ||
StringStream.prototype.pause = function() { | ||
this.paused = true | ||
} | ||
StringStream.prototype.resume = function () { | ||
if (this.paused) this.emit('drain') | ||
this.paused = false | ||
} | ||
function AlignedStringDecoder(encoding) { | ||
@@ -41,0 +63,0 @@ StringDecoder.call(this, encoding) |
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
4410
75