1 // the parent class for all fstreams.
3 module.exports = Abstract
5 var Stream = require('stream').Stream
6 var inherits = require('inherits')
12 inherits(Abstract, Stream)
14 Abstract.prototype.on = function (ev, fn) {
15 if (ev === 'ready' && this.ready) {
16 process.nextTick(fn.bind(this))
18 Stream.prototype.on.call(this, ev, fn)
23 Abstract.prototype.abort = function () {
28 Abstract.prototype.destroy = function () {}
30 Abstract.prototype.warn = function (msg, code) {
32 var er = decorate(msg, code, self)
33 if (!self.listeners('warn')) {
34 console.error('%s %s\n' +
37 'fstream_type = %s\n' +
38 'fstream_path = %s\n' +
39 'fstream_unc_path = %s\n' +
40 'fstream_class = %s\n' +
41 'fstream_stack =\n%s\n',
50 er.fstream_stack.join('\n'))
56 Abstract.prototype.info = function (msg, code) {
57 this.emit('info', msg, code)
60 Abstract.prototype.error = function (msg, code, th) {
61 var er = decorate(msg, code, this)
63 else this.emit('error', er)
66 function decorate (er, code, self) {
67 if (!(er instanceof Error)) er = new Error(er)
68 er.code = er.code || code
69 er.path = er.path || self.path
70 er.fstream_type = er.fstream_type || self.type
71 er.fstream_path = er.fstream_path || self.path
72 if (self._path !== self.path) {
73 er.fstream_unc_path = er.fstream_unc_path || self._path
76 er.fstream_linkpath = er.fstream_linkpath || self.linkpath
78 er.fstream_class = er.fstream_class || self.constructor.name
79 er.fstream_stack = er.fstream_stack ||
80 new Error().stack.split(/\n/).slice(3).map(function (s) {
81 return s.replace(/^ {4}at /, '')