[Pkg-javascript-commits] [node-ytdl-core] 05/08: add patch to bundle jstream

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Sep 12 23:23:04 UTC 2014


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

andrewrk-guest pushed a commit to branch master
in repository node-ytdl-core.

commit 8e7e53e764aebd15b389a16d3741576a93ef2815
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Fri Sep 12 23:16:43 2014 +0000

    add patch to bundle jstream
---
 debian/control                      |   1 -
 debian/patches/bundle-jstream.patch | 234 ++++++++++++++++++++++++++++++++++++
 debian/patches/series               |   1 +
 3 files changed, 235 insertions(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index 6c20879..f3110ae 100644
--- a/debian/control
+++ b/debian/control
@@ -19,7 +19,6 @@ Depends:
  ${misc:Depends}
  , nodejs
  , node-request (>= 2.26.1)
- , node-jstream (>= 0.2.7)
  , node-underscore (>= 1.4.4)
 Description: YouTube video downloader - Node.js module
  ytdl-core is a Node.js module which provides an API to get a readable stream
diff --git a/debian/patches/bundle-jstream.patch b/debian/patches/bundle-jstream.patch
new file mode 100644
index 0000000..f045274
--- /dev/null
+++ b/debian/patches/bundle-jstream.patch
@@ -0,0 +1,234 @@
+Description: bundle jstream module
+ jstream is tiny, by the same author, and only depended on by ytdl-core.
+ Note that we also replace require('readable-stream') with require('stream').
+Author: Andrew Kelley <superjoe30 at gmail.com>
+Forwarded: not-needed
+
+--- /dev/null
++++ node-ytdl-core-0.2.4/node_modules/jstream/lib/index.js
+@@ -0,0 +1,176 @@
++var Transform = require('stream').Transform;
++var util      = require('util');
++var clarinet  = require('clarinet');
++
++
++/**
++ * @constructor
++ * @extends {Transform}
++ */
++var JStream = module.exports = function(path) {
++  Transform.call(this, { objectMode: true });
++
++  var parser = this.parser = new clarinet.createStream()
++    , self = this
++    , stack = []
++    , currObj = {}
++    , currKey = 'root'
++    , inArray
++    , pathMatch = true
++    , parentPathMatch = true
++    , comparator
++    ;
++
++  if (path) {
++    // add some listeners only if path is given
++    var onvaluepath = function onvaluepath(value) {
++      if (pathMatch && stack.length === path.length &&
++          match(currKey, comparator)) {
++        self.push(value);
++      }
++    };
++
++    var onopenpath = function onopenpath() {
++      if (stack.length) {
++        parentPathMatch = pathMatch = parentPathMatch &&
++          comparator !== undefined &&
++          match(currKey, comparator);
++      }
++
++      comparator = path[stack.length];
++    };
++
++    parser.on('value', onvaluepath);
++    parser.on('openobject', onopenpath);
++    parser.on('openarray', onopenpath);
++  }
++
++
++  parser.on('value', function onvalue(value) {
++    currObj[currKey] = value;
++    if (inArray) {
++      currKey++;
++    }
++  });
++
++  parser.on('key', function onkey(key) {
++    currKey = key;
++  });
++  
++  function onopen(key) {
++    var obj, openArray;
++
++    if (key === undefined) {
++      // openarray
++      obj = currObj[currKey] = [];
++      openArray = true;
++      key = 0;
++
++    } else {
++      // openobject
++      obj = currObj[currKey] = {};
++      openArray = false;
++    }
++
++    stack.push({
++      obj: currObj
++    , key: currKey + (inArray ? 1 : '')
++    , arr: inArray
++    , path: pathMatch
++    });
++
++    currObj = obj;
++    currKey = key;
++    inArray = openArray;
++  }
++
++  function onclose() {
++    var current = stack.pop();
++    currObj     = current.obj;
++    currKey     = current.key;
++    inArray     = current.arr;
++    parentPathMatch = stack.length ? stack[stack.length - 1].path : true;
++  }
++
++  parser.on('openobject', onopen);
++  parser.on('closeobject', onclose);
++  parser.on('openarray', onopen);
++  parser.on('closearray', onclose);
++
++  parser.on('error', function onerror(err) {
++    self.readable = false;
++    self.writable = false;
++    parser.emit = function() {};
++    self.emit('error', err);
++  });
++
++  parser.on('end', self.push.bind(self, null));
++
++  if (path) {
++    var onclosepath = function onclosepath() {
++      if (pathMatch && stack.length === path.length) {
++        self.push(currObj[currKey]);
++      }
++      comparator = path[stack.length - 1];
++    };
++
++    parser.on('closeobject', onclosepath);
++    parser.on('closearray', onclosepath);
++
++  } else {
++    // if `path` is not given, emit `data` event whenever a full
++    // objectd on the root is parsed
++    parser.on('closeobject', function onobjectavailable() {
++      if (!stack.length || stack.length === 1 && inArray) {
++        var key = inArray ? currKey - 1 : currKey;
++        self.push(currObj[key]);
++      }
++    });
++  }
++
++};
++util.inherits(JStream, Transform);
++
++
++/**
++ * Writes to the parser.
++ *
++ * @param {Buffer|String} chunk
++ * @param {String} encoding
++ * @param {Function(!Error)} callback
++ */
++JStream.prototype._transform = function(chunk, encoding, callback) {
++  this.parser.write(chunk);
++  callback(null);
++};
++
++
++/**
++ * Compare a key against a string, number, RegExp, boolean, or function.
++ *
++ * @param {String} key
++ * @param {String|Number|RegExp|Boolean|Function} comparator
++ * @return {Boolean}
++ */
++function match(key, comparator) {
++  switch (typeof comparator) {
++    case 'string':
++    case 'number':
++      return key === comparator;
++
++    case 'boolean':
++      return comparator;
++
++    case 'function':
++      return comparator(key);
++
++    case 'object':
++      if (comparator instanceof RegExp) {
++        return comparator.test(key);
++      }
++      break;
++
++  }
++
++  throw new TypeError('Path object not supported.');
++}
+--- /dev/null
++++ node-ytdl-core-0.2.4/node_modules/jstream/package.json
+@@ -0,0 +1,46 @@
++{
++  "name": "jstream",
++  "description": "Continously reads in JSON and outputs Javascript objects.",
++  "keywords": [
++    "stream",
++    "json",
++    "parse",
++    "api"
++  ],
++  "version": "0.2.7",
++  "repository": {
++    "type": "git",
++    "url": "git://github.com/fent/node-jstream.git"
++  },
++  "author": {
++    "name": "Roly Fentanes",
++    "url": "https://github.com/fent"
++  },
++  "main": "./lib/index.js",
++  "scripts": {
++    "test": "mocha -R spec --ignore-leaks test/*-test.js"
++  },
++  "directories": {
++    "lib": "./lib"
++  },
++  "dependencies": {
++    "clarinet": "~0.8.1",
++    "readable-stream": "~1.1.9"
++  },
++  "devDependencies": {
++    "mocha": "*"
++  },
++  "licenses": [
++    {
++      "type": "MIT",
++      "url": "http://github.com/fent/node-jstream/raw/master/LICENSE"
++    }
++  ],
++  "readme": "# node-jstream [![Build Status](https://secure.travis-ci.org/fent/node-jstream.png)](http://travis-ci.org/fent/node-jstream)\n\nContinuously reads in JSON and outputs Javascript objects. Meant to be used with keep-alive connections that send back JSON on updates.\n\n# Usage\n\n```js\nvar JStream = require('jstream');\nvar request = require('request');\n\nrequest('http://api.myhost.com/updates.json')\n  .pipe(new JStream()).on('data', function(obj) {\n    console.log('new js [...]
++  "readmeFilename": "README.md",
++  "bugs": {
++    "url": "https://github.com/fent/node-jstream/issues"
++  },
++  "_id": "jstream at 0.2.7",
++  "_from": "jstream@~0.2.7"
++}
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..f51ae75
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+bundle-jstream.patch

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



More information about the Pkg-javascript-commits mailing list