1 | 'use strict';
|
2 |
|
3 | var constants = process.binding('constants');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function FileDescriptor(flags) {
|
13 |
|
14 | |
15 |
|
16 |
|
17 |
|
18 | this._flags = flags;
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 | this._item = null;
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | this._position = 0;
|
31 |
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | FileDescriptor.prototype.setItem = function(item) {
|
40 | this._item = item;
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | FileDescriptor.prototype.getItem = function() {
|
49 | return this._item;
|
50 | };
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | FileDescriptor.prototype.getPosition = function() {
|
58 | return this._position;
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | FileDescriptor.prototype.setPosition = function(position) {
|
67 | this._position = position;
|
68 | };
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | FileDescriptor.prototype.isAppend = function() {
|
76 | return ((this._flags & constants.O_APPEND) === constants.O_APPEND);
|
77 | };
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | FileDescriptor.prototype.isCreate = function() {
|
85 | return ((this._flags & constants.O_CREAT) === constants.O_CREAT);
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | FileDescriptor.prototype.isRead = function() {
|
94 |
|
95 | return (this._flags === constants.O_RDONLY) ||
|
96 | (this._flags === (constants.O_RDONLY | constants.O_SYNC)) ||
|
97 | ((this._flags & constants.O_RDWR) === constants.O_RDWR);
|
98 | };
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | FileDescriptor.prototype.isWrite = function() {
|
106 | return ((this._flags & constants.O_WRONLY) === constants.O_WRONLY) ||
|
107 | ((this._flags & constants.O_RDWR) === constants.O_RDWR);
|
108 | };
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | FileDescriptor.prototype.isTruncate = function() {
|
116 | return (this._flags & constants.O_TRUNC) === constants.O_TRUNC;
|
117 | };
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | FileDescriptor.prototype.isExclusive = function() {
|
125 | return ((this._flags & constants.O_EXCL) === constants.O_EXCL);
|
126 | };
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | exports = module.exports = FileDescriptor;
|