Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade fstream

  • Loading branch information...
commit 1a55161328bb6f431bdf65c8902b6ca073192a2a 1 parent 0d8f5ca
@isaacs isaacs authored
View
5 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) {
View
78 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
View
1  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))
View
21 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()
}
}
View
3  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")
View
6 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"
View
2  package.json
@@ -47,7 +47,7 @@
"request": "~2.9",
"which": "1",
"tar": "~0.1.12",
- "fstream": "~0.1.13",
+ "fstream": "~0.1.15",
"block-stream": "*",
"inherits": "1",
"mkdirp": "0.3",
Please sign in to comment.
Something went wrong with that request. Please try again.