[Pkg-javascript-commits] [node-resumer] 01/08: Imported Upstream version 0.0.0

Ross Gammon ross-guest at moszumanska.debian.org
Fri Nov 18 19:28:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

ross-guest pushed a commit to branch master
in repository node-resumer.

commit 266d8bdbbdba2a2d6861525700f6bed1f72ba001
Author: Ross Gammon <rossgammon at mail.dk>
Date:   Fri Nov 18 19:32:49 2016 +0100

    Imported Upstream version 0.0.0
---
 .travis.yml       |  4 ++++
 LICENSE           | 18 +++++++++++++++++
 example/resume.js |  8 ++++++++
 index.js          | 29 +++++++++++++++++++++++++++
 package.json      | 45 ++++++++++++++++++++++++++++++++++++++++++
 readme.markdown   | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/resume.js    | 37 ++++++++++++++++++++++++++++++++++
 test/through.js   | 36 +++++++++++++++++++++++++++++++++
 8 files changed, 236 insertions(+)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cc4dba2
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - "0.8"
+  - "0.10"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ee27ba4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+This software is released under the MIT license:
+
+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.
diff --git a/example/resume.js b/example/resume.js
new file mode 100644
index 0000000..d04e61a
--- /dev/null
+++ b/example/resume.js
@@ -0,0 +1,8 @@
+var resumer = require('../');
+createStream().pipe(process.stdout);
+
+function createStream () {
+    var stream = resumer();
+    stream.queue('beep boop\n');
+    return stream;
+}
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..14de798
--- /dev/null
+++ b/index.js
@@ -0,0 +1,29 @@
+var through = require('through');
+var nextTick = typeof setImmediate !== 'undefined'
+    ? setImmediate
+    : process.nextTick
+;
+
+module.exports = function (write, end) {
+    var tr = through(write, end);
+    tr.pause();
+    var resume = tr.resume;
+    var pause = tr.pause;
+    var paused = false;
+    
+    tr.pause = function () {
+        paused = true;
+        return pause.apply(this, arguments);
+    };
+    
+    tr.resume = function () {
+        paused = false;
+        return resume.apply(this, arguments);
+    };
+    
+    nextTick(function () {
+        if (!paused) tr.resume();
+    });
+    
+    return tr;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..22c84b6
--- /dev/null
+++ b/package.json
@@ -0,0 +1,45 @@
+{
+    "name": "resumer",
+    "version": "0.0.0",
+    "description": "a through stream that starts paused and resumes on the next tick",
+    "main": "index.js",
+    "dependencies": {
+        "through": "~2.3.4"
+    },
+    "devDependencies": {
+        "tap": "~0.4.0",
+        "tape": "~1.0.2",
+        "concat-stream": "~0.1.1"
+    },
+    "scripts": {
+        "test": "tap test/*.js"
+    },
+    "testling" : {
+        "files" : "test/*.js",
+        "browsers" : [
+            "ie/6..latest",
+            "chrome/20..latest",
+            "firefox/10..latest",
+            "safari/latest",
+            "opera/11.0..latest",
+            "iphone/6", "ipad/6"
+        ]
+    },
+    "repository": {
+        "type": "git",
+        "url": "git://github.com/substack/resumer.git"
+    },
+    "homepage": "https://github.com/substack/resumer",
+    "keywords": [
+        "through",
+        "stream",
+        "pause",
+        "resume"
+    ],
+    "author": {
+        "name": "James Halliday",
+        "email": "mail at substack.net",
+        "url": "http://substack.net"
+    },
+    "license": "MIT"
+}
diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..5d9df66
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,59 @@
+# resumer
+
+Return a through stream that starts out paused and resumes on the next tick,
+unless somebody called `.pause()`.
+
+This module has the same signature as
+[through](https://npmjs.com/package/through).
+
+[![browser support](https://ci.testling.com/substack/resumer.png)](http://ci.testling.com/substack/resumer)
+
+[![build status](https://secure.travis-ci.org/substack/resumer.png)](http://travis-ci.org/substack/resumer)
+
+# example
+
+``` js
+var resumer = require('resumer');
+var s = createStream();
+s.pipe(process.stdout);
+
+function createStream () {
+    var stream = resumer();
+    stream.queue('beep boop\n');
+    return stream;
+}
+```
+
+```
+$ node example/resume.js
+beep boop
+```
+
+# methods
+
+``` js
+var resumer = require('resumer')
+```
+
+## resumer(write, end)
+
+Return a new through stream from `write` and `end`, which default to
+pass-through `.queue()` functions if not specified.
+
+The stream starts out paused and will be resumed on the next tick unless you
+call `.pause()` first.
+
+`write` and `end` get passed directly through to
+[through](https://npmjs.com/package/through).
+
+# install
+
+With [npm](https://npmjs.org) do:
+
+```
+npm install resumer
+```
+
+# license
+
+MIT
diff --git a/test/resume.js b/test/resume.js
new file mode 100644
index 0000000..1eaecac
--- /dev/null
+++ b/test/resume.js
@@ -0,0 +1,37 @@
+var test = require('tape');
+var resumer = require('../');
+var concat = require('concat-stream');
+
+test('implicit resume', function (t) {
+    t.plan(1);
+    
+    var s = createStream();
+    s.pipe(concat(function (err, body) {
+        t.equal(body, 'beep boop\n');
+    }));
+});
+
+test('pause/resume', function (t) {
+    t.plan(2);
+    
+    var s = createStream();
+    s.pause();
+    
+    var paused = true;
+    setTimeout(function () {
+        paused = false;
+        s.resume();
+    }, 100);
+    
+    s.pipe(concat(function (err, body) {
+        t.equal(paused, false);
+        t.equal(body, 'beep boop\n');
+    }));
+});
+
+function createStream () {
+    var stream = resumer();
+    stream.queue('beep boop\n');
+    stream.queue(null);
+    return stream;
+}
diff --git a/test/through.js b/test/through.js
new file mode 100644
index 0000000..ddcaf48
--- /dev/null
+++ b/test/through.js
@@ -0,0 +1,36 @@
+var test = require('tape');
+var resumer = require('../');
+var concat = require('concat-stream');
+
+test('through write/end', function (t) {
+    t.plan(2);
+    
+    var s = createStream();
+    
+    s.on('okok', function () {
+        t.ok(true);
+    });
+    
+    s.pipe(concat(function (err, body) {
+        t.equal(body, 'BEGIN\nRAWR\nEND\n');
+    }));
+    
+    setTimeout(function () {
+        s.end('rawr\n');
+    }, 50);
+});
+
+function createStream () {
+    var stream = resumer(write, end);
+    stream.queue('BEGIN\n');
+    return stream;
+    
+    function write (x) {
+        this.queue(String(x).toUpperCase());
+    }
+    function end () {
+        this.emit('okok');
+        this.queue('END\n');
+        this.queue(null);
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-resumer.git



More information about the Pkg-javascript-commits mailing list