Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added .join and .replace, and bumped version 0.6.0

  • Loading branch information...
commit b5cfae7b257dee2298bc83e2a247cb109603a937 1 parent c8bbd1a
@dominictarr authored
Showing with 67 additions and 6 deletions.
  1. +22 −0 LICENCE
  2. +44 −5 index.js
  3. +1 −1  package.json
View
22 LICENCE
@@ -0,0 +1,22 @@
+Copyright (c) 2011 Dominic Tarr
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
49 index.js
@@ -337,7 +337,8 @@ es.split = function (matcher) {
}
stream.end = function () {
- stream.emit('data', soFar)
+ if(soFar)
+ stream.emit('data', soFar)
stream.emit('end')
}
@@ -362,7 +363,6 @@ es.gate = function (shut) {
, ended = false
shut = (shut === false ? false : true) //default to shut
-// console.error('SHUT?', shut)
stream.writable = true
stream.readable = true
@@ -372,7 +372,6 @@ es.gate = function (shut) {
stream.open = function () { shut = false; maybe() }
function maybe () {
-// console.error('maybe', queue.length, shut)
while(queue.length && !shut) {
var args = queue.shift()
args.unshift('data')
@@ -387,8 +386,7 @@ es.gate = function (shut) {
var args = [].slice.call(arguments)
queue.push(args)
-// console.error(queue)
- if (shut) return false //pause up stream pipes
+ if (shut) return //false //pause up stream pipes
maybe()
}
@@ -422,6 +420,47 @@ es.stringify = function () {
}
//
+// replace a string within a stream.
+//
+// warn: just concatenates the string and then does str.split().join().
+// probably not optimal.
+// for smallish responses, who cares?
+// I need this for shadow-npm so it's only relatively small json files.
+
+es.replace = function (from, to) {
+ var stream = new Stream()
+ var body = ''
+ stream.readable = true
+ stream.writable = true
+ stream.write = function (data) { body += data }
+ stream.end = function (data) {
+ if(data)
+ body += data
+
+ stream.emit('data', body.split(from).join(to))
+ stream.emit('end')
+ }
+ return stream
+}
+
+es.join = function (callback) {
+ var stream = new Stream()
+ var body = ''
+ stream.readable = true
+ stream.writable = true
+ stream.write = function (data) { body += data }
+ stream.end = function (data) {
+ if(data)
+ body += data
+ if(callback)
+ callback(null, body)
+ stream.emit('data', body)
+ stream.emit('end')
+ }
+ return stream
+}
+
+//
// helper to make your module into a unix pipe
// simply add
//
View
2  package.json
@@ -1,5 +1,5 @@
{ "name": "event-stream"
-, "version": "0.5.3"
+, "version": "0.6.0"
, "description": "construct pipes of streams of events"
, "homepage": "http://github.com/dominictarr/event-stream"
, "repository":
Please sign in to comment.
Something went wrong with that request. Please try again.