-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
65 lines (60 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
var PauseWrapper = require('./PauseWrapper.js')
var inherits = require('inherits')
module.exports = RASPauseWrapper
function RASPauseWrapper (ras) {
if (!(this instanceof RASPauseWrapper)) {
return new RASPauseWrapper(ras)
}
PauseWrapper.call(this, ras)
this.opened = false
this.closed = false
this.destroyed = false
this.readable = ras.readable
this.writeable = ras.writeable
this.deletable = ras.deletable
this.preferReadonly = ras.preferReadonly
}
inherits(RASPauseWrapper, PauseWrapper)
Object.assign(RASPauseWrapper.prototype, {
open: function (cb) {
var scope = this
this._onResumeCb(cb, function (cbProxy) {
this._proxied.open(function (err) {
if (err) return cbProxy(err)
scope.opened = true
cbProxy()
})
})
},
read: function (offset, size, cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.read(offset, size, cbProxy) })
},
write: function (offset, buffer, cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.write(offset, buffer, cbProxy) })
},
del: function (offset, size, cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.del(offset, size, cbProxy) })
},
stat: function (cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.stat(cbProxy) })
},
close: function (cb) {
this._closed = true
var scope = this
return this._proxied.close(function (err) {
if (err) return cb(err)
scope.closed = true
cb()
})
},
destroy: function (cb) {
this._closed = true
var scope = this
return this._proxied.destroy(function (err) {
if (err) return cb(err)
scope.destroyed = true
cb()
})
}
})