Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions examples/filter-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ function missile (entry) {
return function (c) {
var e = Math.random() < 0.5
console.error(indent + '%s %s for %d damage!',
entry.basename,
e ? 'is struck' : 'fires a chunk',
c.length)
entry.basename,
e ? 'is struck' : 'fires a chunk',
c.length)
}
}

function runaway (entry) {
return function () {
var e = Math.random() < 0.5
console.error(indent + '%s %s',
entry.basename,
e ? 'turns to flee' : 'is vanquished!')
entry.basename,
e ? 'turns to flee' : 'is vanquished!')
indent = indent.slice(0, -1)
}
}
Expand All @@ -101,7 +101,7 @@ w.on('entry', attacks)
// w.on('ready', function () { attacks(w) })
function attacks (entry) {
console.error(indent + '%s %s!', entry.basename,
entry.type === 'Directory' ? 'calls for backup' : 'attacks')
entry.type === 'Directory' ? 'calls for backup' : 'attacks')
entry.on('entry', attacks)
}

Expand All @@ -121,13 +121,14 @@ r.on('end', function () {
checker.on('child', function (e) {
var ok = e.type === 'Directory'
console.log((ok ? '' : 'not ') + 'ok ' + (i++) +
' should be a dir: ' +
e.path.substr(checker.path.length + 1))
' should be a dir: ' +
e.path.substr(checker.path.length + 1))
})
})

process.on('exit', function () {
console.log((ended ? '' : 'not ') + 'ok ' + (i++) + ' ended')
console.log((ended ? '' : 'not ') + 'ok ' + (i) + ' ended')
console.log('1..' + i)
})

r.pipe(w)
17 changes: 9 additions & 8 deletions examples/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var r = fstream.Reader({
path: path.dirname(__dirname),
filter: function () {
return !this.basename.match(/^\./) &&
!this.basename.match(/^node_modules$/) &&
!this.basename.match(/^deep-copy$/)
!this.basename.match(/^node_modules$/) &&
!this.basename.match(/^deep-copy$/)
}
})

Expand Down Expand Up @@ -76,18 +76,18 @@ function missile (entry) {
return function (c) {
var e = Math.random() < 0.5
console.error(indent + '%s %s for %d damage!',
entry.basename,
e ? 'is struck' : 'fires a chunk',
c.length)
entry.basename,
e ? 'is struck' : 'fires a chunk',
c.length)
}
}

function runaway (entry) {
return function () {
var e = Math.random() < 0.5
console.error(indent + '%s %s',
entry.basename,
e ? 'turns to flee' : 'is vanquished!')
entry.basename,
e ? 'turns to flee' : 'is vanquished!')
indent = indent.slice(0, -1)
}
}
Expand All @@ -96,7 +96,7 @@ w.on('entry', attacks)
// w.on('ready', function () { attacks(w) })
function attacks (entry) {
console.error(indent + '%s %s!', entry.basename,
entry.type === 'Directory' ? 'calls for backup' : 'attacks')
entry.type === 'Directory' ? 'calls for backup' : 'attacks')
entry.on('entry', attacks)
}

Expand All @@ -112,6 +112,7 @@ r.on('end', function () {

process.on('exit', function () {
console.log((ended ? '' : 'not ') + 'ok 2 ended')
console.log('1..2')
})

r.pipe(w)
2 changes: 2 additions & 0 deletions examples/symlink-write.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fstream = require('../fstream.js')
var notOpen = false
process.chdir(__dirname)

fstream
.Writer({
Expand All @@ -22,4 +23,5 @@ fstream

process.on('exit', function () {
console.log((notOpen ? '' : 'not ') + 'ok 3 should be closed')
console.log('1..3')
})
32 changes: 16 additions & 16 deletions lib/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ Abstract.prototype.warn = function (msg, code) {
var er = decorate(msg, code, self)
if (!self.listeners('warn')) {
console.error('%s %s\n' +
'path = %s\n' +
'syscall = %s\n' +
'fstream_type = %s\n' +
'fstream_path = %s\n' +
'fstream_unc_path = %s\n' +
'fstream_class = %s\n' +
'fstream_stack =\n%s\n',
code || 'UNKNOWN',
er.stack,
er.path,
er.syscall,
er.fstream_type,
er.fstream_path,
er.fstream_unc_path,
er.fstream_class,
er.fstream_stack.join('\n'))
'path = %s\n' +
'syscall = %s\n' +
'fstream_type = %s\n' +
'fstream_path = %s\n' +
'fstream_unc_path = %s\n' +
'fstream_class = %s\n' +
'fstream_stack =\n%s\n',
code || 'UNKNOWN',
er.stack,
er.path,
er.syscall,
er.fstream_type,
er.fstream_path,
er.fstream_unc_path,
er.fstream_class,
er.fstream_stack.join('\n'))
} else {
self.emit('warn', er)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/dir-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function DirWriter (props) {
// should already be established as a Directory type
if (props.type !== 'Directory' || !props.Directory) {
self.error('Non-directory type ' + props.type + ' ' +
JSON.stringify(props), null, true)
JSON.stringify(props), null, true)
}

Writer.call(this, props)
Expand Down Expand Up @@ -102,7 +102,7 @@ DirWriter.prototype._process = function () {
do {
pp = p._path || p.path
if (pp === self.root._path || pp === self._path ||
(pp && pp.indexOf(self._path) === 0)) {
(pp && pp.indexOf(self._path) === 0)) {
// console.error('DW Exit (recursive)', entry.basename, self._path)
self._processing = false
if (entry._collected) entry.pipe()
Expand Down
10 changes: 5 additions & 5 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function FileReader (props) {
// XXX Todo: preserve hardlinks by tracking dev+inode+nlink,
// with a HardLinkReader class.
if (!((props.type === 'Link' && props.Link) ||
(props.type === 'File' && props.File))) {
(props.type === 'File' && props.File))) {
throw new Error('Non-file type ' + props.type)
}

Expand Down Expand Up @@ -63,8 +63,8 @@ FileReader.prototype._getStream = function () {

if (self._bytesEmitted !== self.props.size) {
self.error("Didn't get expected byte count\n" +
'expect: ' + self.props.size + '\n' +
'actual: ' + self._bytesEmitted)
'expect: ' + self.props.size + '\n' +
'actual: ' + self._bytesEmitted)
}
})

Expand Down Expand Up @@ -124,8 +124,8 @@ FileReader.prototype._read = function () {
}
self._buffer.length = 0
}
// console.error("FR _read done")
// that's about all there is to it.
// console.error("FR _read done")
// that's about all there is to it.
}

FileReader.prototype.pause = function (who) {
Expand Down
2 changes: 1 addition & 1 deletion lib/link-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function LinkReader (props) {
}

if (!((props.type === 'Link' && props.Link) ||
(props.type === 'SymbolicLink' && props.SymbolicLink))) {
(props.type === 'SymbolicLink' && props.SymbolicLink))) {
throw new Error('Non-link type ' + props.type)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/link-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function LinkWriter (props) {

// should already be established as a Link type
if (!((props.type === 'Link' && props.Link) ||
(props.type === 'SymbolicLink' && props.SymbolicLink))) {
(props.type === 'SymbolicLink' && props.SymbolicLink))) {
throw new Error('Non-link type ' + props.type)
}

Expand Down Expand Up @@ -66,8 +66,8 @@ function create (self, lp, link) {
// windows in some nice fashion.
if (er) {
if ((er.code === 'ENOENT' ||
er.code === 'EACCES' ||
er.code === 'EPERM') && process.platform === 'win32') {
er.code === 'EACCES' ||
er.code === 'EPERM') && process.platform === 'win32') {
self.ready = true
self.emit('ready')
self.emit('end')
Expand Down
24 changes: 12 additions & 12 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ function Reader (props, currentStat) {
break

case 'Link':
// XXX hard links are just files.
// However, it would be good to keep track of files' dev+inode
// and nlink values, and create a HardLinkReader that emits
// a linkpath value of the original copy, so that the tar
// writer can preserve them.
// ClassType = HardLinkReader
// break
// XXX hard links are just files.
// However, it would be good to keep track of files' dev+inode
// and nlink values, and create a HardLinkReader that emits
// a linkpath value of the original copy, so that the tar
// writer can preserve them.
// ClassType = HardLinkReader
// break

case 'File':
ClassType = require('./file-reader.js')
Expand Down Expand Up @@ -103,7 +103,7 @@ function Reader (props, currentStat) {
self._swallowErrors = true
// if (self._path.indexOf(" ") === -1) {
self._path = '\\\\?\\' + self.path.replace(/\//g, '\\')
// }
// }
}
}
self.basename = props.basename = path.basename(self.path)
Expand All @@ -126,10 +126,10 @@ function Reader (props, currentStat) {

function alphasort (a, b) {
return a === b ? 0
: a.toLowerCase() > b.toLowerCase() ? 1
: a.toLowerCase() < b.toLowerCase() ? -1
: a > b ? 1
: -1
: a.toLowerCase() > b.toLowerCase() ? 1
: a.toLowerCase() < b.toLowerCase() ? -1
: a > b ? 1
: -1
}

Reader.prototype._stat = function (currentStat) {
Expand Down
18 changes: 9 additions & 9 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Writer.prototype._create = function () {
fs[self.props.follow ? 'stat' : 'lstat'](self._path, function (er) {
if (er) {
return self.warn('Cannot create ' + self._path + '\n' +
'Unsupported type: ' + self.type, 'ENOTSUP')
'Unsupported type: ' + self.type, 'ENOTSUP')
}
self._finish()
})
Expand Down Expand Up @@ -179,7 +179,7 @@ function create (self) {
function endChmod (self, want, current, path, cb) {
var wantMode = want.mode
var chmod = want.follow || self.type !== 'SymbolicLink'
? 'chmod' : 'lchmod'
? 'chmod' : 'lchmod'

if (!fs[chmod]) return cb()
if (typeof wantMode !== 'number') return cb()
Expand All @@ -196,13 +196,13 @@ function endChown (self, want, current, path, cb) {
if (process.platform === 'win32') return cb()
if (!process.getuid || process.getuid() !== 0) return cb()
if (typeof want.uid !== 'number' &&
typeof want.gid !== 'number') return cb()
typeof want.gid !== 'number') return cb()

if (current.uid === want.uid &&
current.gid === want.gid) return cb()
current.gid === want.gid) return cb()

var chown = (self.props.follow || self.type !== 'SymbolicLink')
? 'chown' : 'lchown'
? 'chown' : 'lchown'
if (!fs[chown]) return cb()

if (typeof want.uid !== 'number') want.uid = current.uid
Expand All @@ -215,7 +215,7 @@ function endUtimes (self, want, current, path, cb) {
if (!fs.utimes || process.platform === 'win32') return cb()

var utimes = (want.follow || self.type !== 'SymbolicLink')
? 'utimes' : 'lutimes'
? 'utimes' : 'lutimes'

if (utimes === 'lutimes' && !fs[utimes]) {
utimes = 'utimes'
Expand All @@ -235,7 +235,7 @@ function endUtimes (self, want, current, path, cb) {
if (!isDate(meM)) meA = new Date(meM)

if (meA.getTime() === curA.getTime() &&
meM.getTime() === curM.getTime()) return cb()
meM.getTime() === curM.getTime()) return cb()

fs[utimes](path, meA, meM, cb)
}
Expand Down Expand Up @@ -274,8 +274,8 @@ Writer.prototype._finish = function () {
// doesn't exist yet (especially if it was intended as a symlink),
// so swallow ENOENT errors here and just soldier on.
if (er.code === 'ENOENT' &&
(self.type === 'Link' || self.type === 'SymbolicLink') &&
process.platform === 'win32') {
(self.type === 'Link' || self.type === 'SymbolicLink') &&
process.platform === 'win32') {
self.ready = true
self.emit('ready')
self.emit('end')
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"rimraf": "2"
},
"devDependencies": {
"tap": "0",
"standard": "^2.3.2"
"standard": "^4.0.0",
"tap": "^1.2.0"
},
"scripts": {
"test": "standard && tap examples/*.js"
Expand Down