Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-03-27 01:34:59 +0400
committerisaacs <i@izs.me>2012-03-27 01:34:59 +0400
commit1a55161328bb6f431bdf65c8902b6ca073192a2a (patch)
treed98b18869dd7a694e23e7dde0fc902c59a02ea44 /node_modules/fstream
parent0d8f5ca337c4b65bff2c240862e75aca921ce96c (diff)
Upgrade fstream
Diffstat (limited to 'node_modules/fstream')
-rw-r--r--node_modules/fstream/lib/abstract.js5
-rw-r--r--node_modules/fstream/lib/dir-reader.js78
-rw-r--r--node_modules/fstream/lib/proxy-reader.js1
-rw-r--r--node_modules/fstream/lib/reader.js21
-rw-r--r--node_modules/fstream/lib/writer.js3
-rw-r--r--node_modules/fstream/package.json6
6 files changed, 84 insertions, 30 deletions
diff --git a/node_modules/fstream/lib/abstract.js b/node_modules/fstream/lib/abstract.js
index add48b945..5675d4a1b 100644
--- a/node_modules/fstream/lib/abstract.js
+++ b/node_modules/fstream/lib/abstract.js
@@ -20,6 +20,11 @@ Abstract.prototype.on = function (ev, fn) {
return this
}
+Abstract.prototype.abort = function () {
+ this._aborted = true
+ this.emit("abort")
+}
+
Abstract.prototype.destroy = function () {}
Abstract.prototype.warn = function (msg, code) {
diff --git a/node_modules/fstream/lib/dir-reader.js b/node_modules/fstream/lib/dir-reader.js
index ab990d150..08ecf13ac 100644
--- a/node_modules/fstream/lib/dir-reader.js
+++ b/node_modules/fstream/lib/dir-reader.js
@@ -11,6 +11,7 @@ var fs = require("graceful-fs")
, mkdir = require("mkdirp")
, path = require("path")
, Reader = require("./reader.js")
+ , assert = require("assert").ok
inherits(DirReader, Reader)
@@ -24,7 +25,7 @@ function DirReader (props) {
throw new Error("Non-directory type "+ props.type)
}
- me._entries = null
+ me.entries = null
me._index = -1
me._paused = false
me._length = -1
@@ -36,13 +37,21 @@ DirReader.prototype._getEntries = function () {
var me = this
fs.readdir(me._path, function (er, entries) {
if (er) return me.error(er)
- me._entries = entries
- me._length = entries.length
- // console.error("DR %s sort =", me.path, me.props.sort)
- if (typeof me.props.sort === "function") {
- me._entries.sort(me.props.sort)
+
+ me.entries = entries
+
+ me.emit("entries", entries)
+ if (me._paused) me.once("resume", processEntries)
+ else processEntries()
+
+ function processEntries () {
+ me._length = me.entries.length
+ // console.error("DR %s sort =", me.path, me.props.sort)
+ if (typeof me.props.sort === "function") {
+ me.entries.sort(me.props.sort)
+ }
+ me._read()
}
- me._read()
})
}
@@ -50,7 +59,7 @@ DirReader.prototype._getEntries = function () {
DirReader.prototype._read = function () {
var me = this
- if (!me._entries) return me._getEntries()
+ if (!me.entries) return me._getEntries()
if (me._paused || me._currentEntry || me._aborted) {
// console.error("DR paused=%j, current=%j, aborted=%j", me._paused, !!me._currentEntry, me._aborted)
@@ -70,20 +79,20 @@ DirReader.prototype._read = function () {
// ok, handle this one, then.
// save creating a proxy, by stat'ing the thing now.
- var p = path.resolve(me._path, me._entries[me._index])
+ var p = path.resolve(me._path, me.entries[me._index])
+ assert(p !== me._path)
+ assert(me.entries[me._index])
+
// set this to prevent trying to _read() again in the stat time.
me._currentEntry = p
fs[ me.props.follow ? "stat" : "lstat" ](p, function (er, stat) {
if (er) return me.error(er)
- var entry = Reader({ path: p
- , depth: me.depth + 1
- , root: me.root || me._proxy || me
- , parent: me._proxy || me
- , follow: me.follow
- , filter: me.filter
- , sort: me.props.sort
- }, stat)
+ var who = me._proxy || me
+ var childProps = me.getChildProps.call(who, stat)
+ childProps.path = p
+
+ var entry = Reader(childProps, stat)
// console.error("DR Entry", p, stat.size)
@@ -94,17 +103,21 @@ DirReader.prototype._read = function () {
// This nomenclature is not completely final.
entry.on("pause", function (who) {
- if (!me._paused) {
+ if (!me._paused && !entry._disowned) {
me.pause(who)
}
})
entry.on("resume", function (who) {
- if (me._paused) {
+ if (me._paused && !entry._disowned) {
me.resume(who)
}
})
+ entry.on("stat", function (props) {
+ me.emit("entryStat", entry, props)
+ })
+
entry.on("ready", function EMITCHILD () {
// console.error("DR emit child", entry._path)
if (me._paused) {
@@ -129,16 +142,19 @@ DirReader.prototype._read = function () {
var ended = false
entry.on("close", onend)
+ entry.on("disown", onend)
function onend () {
if (ended) return
ended = true
me.emit("childEnd", entry)
me.emit("entryEnd", entry)
me._currentEntry = null
- me._read()
+ if (!me._paused) {
+ me._read()
+ }
}
- // XXX Make this work in node.
+ // XXX Remove this. Works in node as of 0.6.2 or so.
// Long filenames should not break stuff.
entry.on("error", function (er) {
if (entry._swallowErrors) {
@@ -160,6 +176,26 @@ DirReader.prototype._read = function () {
})
}
+DirReader.prototype.disown = function (entry) {
+ entry.emit("beforeDisown")
+ entry._disowned = true
+ entry.parent = entry.root = null
+ if (entry === this._currentEntry) {
+ this._currentEntry = null
+ }
+ entry.emit("disown")
+}
+
+DirReader.prototype.getChildProps = function (stat) {
+ return { depth: this.depth + 1
+ , root: this.root || this
+ , parent: this
+ , follow: this.follow
+ , filter: this.filter
+ , sort: this.props.sort
+ }
+}
+
DirReader.prototype.pause = function (who) {
var me = this
if (me._paused) return
diff --git a/node_modules/fstream/lib/proxy-reader.js b/node_modules/fstream/lib/proxy-reader.js
index f5ddfc3f5..a0ece34a2 100644
--- a/node_modules/fstream/lib/proxy-reader.js
+++ b/node_modules/fstream/lib/proxy-reader.js
@@ -63,6 +63,7 @@ ProxyReader.prototype._addProxy = function (proxy) {
, "child"
, "childEnd"
, "warn"
+ , "stat"
].forEach(function (ev) {
// console.error("~~ proxy event", ev, me.path)
proxy.on(ev, me.emit.bind(me, ev))
diff --git a/node_modules/fstream/lib/reader.js b/node_modules/fstream/lib/reader.js
index 6aa67ada7..16f0d1ea0 100644
--- a/node_modules/fstream/lib/reader.js
+++ b/node_modules/fstream/lib/reader.js
@@ -187,19 +187,30 @@ Reader.prototype._stat = function (currentStat) {
// if the filter doesn't pass, then just skip over this one.
// still have to emit end so that dir-walking can move on.
if (me.filter) {
+ var who = me._proxy || me
// special handling for ProxyReaders
- if (!me.filter.call(me._proxy || me)) {
- me._aborted = true
- me.emit("end")
- me.emit("close")
+ if (!me.filter.call(who, who, props)) {
+ if (!me._disowned) {
+ me.abort()
+ me.emit("end")
+ me.emit("close")
+ }
return
}
}
+ // last chance to abort or disown before the flow starts!
+ me.emit("stat", props)
+ if (me._aborted) {
+ me.emit("end")
+ me.emit("close")
+ return
+ }
+
me.emit("ready", props)
// if it's a directory, then we'll be emitting "entry" events.
- me._read()
+ if (!me._paused) me._read()
}
}
diff --git a/node_modules/fstream/lib/writer.js b/node_modules/fstream/lib/writer.js
index b7cd261bf..0236165fb 100644
--- a/node_modules/fstream/lib/writer.js
+++ b/node_modules/fstream/lib/writer.js
@@ -123,12 +123,13 @@ Writer.prototype._stat = function (current) {
var me = this
, props = me.props
, stat = props.follow ? "stat" : "lstat"
+ , who = me._proxy || me
if (current) statCb(null, current)
else fs[stat](me._path, statCb)
function statCb (er, current) {
- if (me.filter && !me.filter.call(me._proxy || me, current)) {
+ if (me.filter && !me.filter.call(who, who, current)) {
me._aborted = true
me.emit("end")
me.emit("close")
diff --git a/node_modules/fstream/package.json b/node_modules/fstream/package.json
index 2ad0c6cba..c6cd205a9 100644
--- a/node_modules/fstream/package.json
+++ b/node_modules/fstream/package.json
@@ -6,7 +6,7 @@
},
"name": "fstream",
"description": "Advanced file system stream things",
- "version": "0.1.14",
+ "version": "0.1.15",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/fstream.git"
@@ -32,10 +32,10 @@
"name": "isaacs",
"email": "i@izs.me"
},
- "_id": "fstream@0.1.14",
+ "_id": "fstream@0.1.15",
"optionalDependencies": {},
"_engineSupported": true,
- "_npmVersion": "1.1.10",
+ "_npmVersion": "1.1.12",
"_nodeVersion": "v0.7.7-pre",
"_defaultsLoaded": true,
"_from": "fstream@~0.1.13"