@@ -34,72 +34,72 @@ const {
3434} = require ( 'internal/validators' ) ;
3535
3636class Dir {
37- #dirHandle ;
38- #dirPath ;
39- #dirBufferedEntries ;
40- #dirClosed ;
41- #dirOptions ;
42- #dirReadPromisified ;
43- #dirClosePromisified ;
44- #dirOperationQueue ;
37+ #handle ;
38+ #path ;
39+ #bufferedEntries ;
40+ #closed ;
41+ #options ;
42+ #readPromisified ;
43+ #closePromisified ;
44+ #operationQueue ;
4545
4646 constructor ( handle , path , options ) {
4747 if ( handle == null ) throw new ERR_MISSING_ARGS ( 'handle' ) ;
48- this . #dirHandle = handle ;
49- this . #dirBufferedEntries = [ ] ;
50- this . #dirPath = path ;
51- this . #dirClosed = false ;
48+ this . #handle = handle ;
49+ this . #bufferedEntries = [ ] ;
50+ this . #path = path ;
51+ this . #closed = false ;
5252
5353 // Either `null` or an Array of pending operations (= functions to be called
5454 // once the current operation is done).
55- this . #dirOperationQueue = null ;
55+ this . #operationQueue = null ;
5656
57- this . #dirOptions = {
57+ this . #options = {
5858 bufferSize : 32 ,
5959 ...getOptions ( options , {
6060 encoding : 'utf8' ,
6161 } ) ,
6262 } ;
6363
64- validateUint32 ( this . #dirOptions . bufferSize , 'options.bufferSize' , true ) ;
64+ validateUint32 ( this . #options . bufferSize , 'options.bufferSize' , true ) ;
6565
66- this . #dirReadPromisified = FunctionPrototypeBind (
66+ this . #readPromisified = FunctionPrototypeBind (
6767 internalUtil . promisify ( this . #dirReadImpl) , this , false ) ;
68- this . #dirClosePromisified = FunctionPrototypeBind (
68+ this . #closePromisified = FunctionPrototypeBind (
6969 internalUtil . promisify ( this . close ) , this ) ;
7070 }
7171
7272 get path ( ) {
73- return this . #dirPath ;
73+ return this . #path ;
7474 }
7575
7676 read ( callback ) {
7777 return this . #dirReadImpl( true , callback ) ;
7878 }
7979
8080 #dirReadImpl( maybeSync , callback ) {
81- if ( this . #dirClosed === true ) {
81+ if ( this . #closed === true ) {
8282 throw new ERR_DIR_CLOSED ( ) ;
8383 }
8484
8585 if ( callback === undefined ) {
86- return this . #dirReadPromisified ( ) ;
86+ return this . #readPromisified ( ) ;
8787 }
8888
8989 validateFunction ( callback , 'callback' ) ;
9090
91- if ( this . #dirOperationQueue !== null ) {
92- ArrayPrototypePush ( this . #dirOperationQueue , ( ) => {
91+ if ( this . #operationQueue !== null ) {
92+ ArrayPrototypePush ( this . #operationQueue , ( ) => {
9393 this . #dirReadImpl( maybeSync , callback ) ;
9494 } ) ;
9595 return ;
9696 }
9797
98- if ( this . #dirBufferedEntries . length > 0 ) {
98+ if ( this . #bufferedEntries . length > 0 ) {
9999 try {
100- const dirent = ArrayPrototypeShift ( this . #dirBufferedEntries ) ;
100+ const dirent = ArrayPrototypeShift ( this . #bufferedEntries ) ;
101101
102- if ( this . #dirOptions . recursive && dirent . isDirectory ( ) ) {
102+ if ( this . #options . recursive && dirent . isDirectory ( ) ) {
103103 this . readSyncRecursive ( dirent ) ;
104104 }
105105
@@ -116,8 +116,8 @@ class Dir {
116116 const req = new FSReqCallback ( ) ;
117117 req . oncomplete = ( err , result ) => {
118118 process . nextTick ( ( ) => {
119- const queue = this . #dirOperationQueue ;
120- this . #dirOperationQueue = null ;
119+ const queue = this . #operationQueue ;
120+ this . #operationQueue = null ;
121121 for ( const op of queue ) op ( ) ;
122122 } ) ;
123123
@@ -126,9 +126,9 @@ class Dir {
126126 }
127127
128128 try {
129- this . processReadResult ( this . #dirPath , result ) ;
130- const dirent = ArrayPrototypeShift ( this . #dirBufferedEntries ) ;
131- if ( this . #dirOptions . recursive && dirent . isDirectory ( ) ) {
129+ this . processReadResult ( this . #path , result ) ;
130+ const dirent = ArrayPrototypeShift ( this . #bufferedEntries ) ;
131+ if ( this . #options . recursive && dirent . isDirectory ( ) ) {
132132 this . readSyncRecursive ( dirent ) ;
133133 }
134134 callback ( null , dirent ) ;
@@ -137,18 +137,18 @@ class Dir {
137137 }
138138 } ;
139139
140- this . #dirOperationQueue = [ ] ;
141- this . #dirHandle . read (
142- this . #dirOptions . encoding ,
143- this . #dirOptions . bufferSize ,
140+ this . #operationQueue = [ ] ;
141+ this . #handle . read (
142+ this . #options . encoding ,
143+ this . #options . bufferSize ,
144144 req ,
145145 ) ;
146146 }
147147
148148 processReadResult ( path , result ) {
149149 for ( let i = 0 ; i < result . length ; i += 2 ) {
150150 ArrayPrototypePush (
151- this . #dirBufferedEntries ,
151+ this . #bufferedEntries ,
152152 getDirent (
153153 path ,
154154 result [ i ] ,
@@ -163,14 +163,14 @@ class Dir {
163163 const ctx = { path } ;
164164 const handle = dirBinding . opendir (
165165 pathModule . toNamespacedPath ( path ) ,
166- this . #dirOptions . encoding ,
166+ this . #options . encoding ,
167167 undefined ,
168168 ctx ,
169169 ) ;
170170 handleErrorFromBinding ( ctx ) ;
171171 const result = handle . read (
172- this . #dirOptions . encoding ,
173- this . #dirOptions . bufferSize ,
172+ this . #options . encoding ,
173+ this . #options . bufferSize ,
174174 undefined ,
175175 ctx ,
176176 ) ;
@@ -184,26 +184,26 @@ class Dir {
184184 }
185185
186186 readSync ( ) {
187- if ( this . #dirClosed === true ) {
187+ if ( this . #closed === true ) {
188188 throw new ERR_DIR_CLOSED ( ) ;
189189 }
190190
191- if ( this . #dirOperationQueue !== null ) {
191+ if ( this . #operationQueue !== null ) {
192192 throw new ERR_DIR_CONCURRENT_OPERATION ( ) ;
193193 }
194194
195- if ( this . #dirBufferedEntries . length > 0 ) {
196- const dirent = ArrayPrototypeShift ( this . #dirBufferedEntries ) ;
197- if ( this . #dirOptions . recursive && dirent . isDirectory ( ) ) {
195+ if ( this . #bufferedEntries . length > 0 ) {
196+ const dirent = ArrayPrototypeShift ( this . #bufferedEntries ) ;
197+ if ( this . #options . recursive && dirent . isDirectory ( ) ) {
198198 this . readSyncRecursive ( dirent ) ;
199199 }
200200 return dirent ;
201201 }
202202
203- const ctx = { path : this . #dirPath } ;
204- const result = this . #dirHandle . read (
205- this . #dirOptions . encoding ,
206- this . #dirOptions . bufferSize ,
203+ const ctx = { path : this . #path } ;
204+ const result = this . #handle . read (
205+ this . #options . encoding ,
206+ this . #options . bufferSize ,
207207 undefined ,
208208 ctx ,
209209 ) ;
@@ -213,10 +213,10 @@ class Dir {
213213 return result ;
214214 }
215215
216- this . processReadResult ( this . #dirPath , result ) ;
216+ this . processReadResult ( this . #path , result ) ;
217217
218- const dirent = ArrayPrototypeShift ( this . #dirBufferedEntries ) ;
219- if ( this . #dirOptions . recursive && dirent . isDirectory ( ) ) {
218+ const dirent = ArrayPrototypeShift ( this . #bufferedEntries ) ;
219+ if ( this . #options . recursive && dirent . isDirectory ( ) ) {
220220 this . readSyncRecursive ( dirent ) ;
221221 }
222222 return dirent ;
@@ -225,60 +225,60 @@ class Dir {
225225 close ( callback ) {
226226 // Promise
227227 if ( callback === undefined ) {
228- if ( this . #dirClosed === true ) {
228+ if ( this . #closed === true ) {
229229 return PromiseReject ( new ERR_DIR_CLOSED ( ) ) ;
230230 }
231- return this . #dirClosePromisified ( ) ;
231+ return this . #closePromisified ( ) ;
232232 }
233233
234234 // callback
235235 validateFunction ( callback , 'callback' ) ;
236236
237- if ( this . #dirClosed === true ) {
237+ if ( this . #closed === true ) {
238238 process . nextTick ( callback , new ERR_DIR_CLOSED ( ) ) ;
239239 return ;
240240 }
241241
242- if ( this . #dirOperationQueue !== null ) {
243- ArrayPrototypePush ( this . #dirOperationQueue , ( ) => {
242+ if ( this . #operationQueue !== null ) {
243+ ArrayPrototypePush ( this . #operationQueue , ( ) => {
244244 this . close ( callback ) ;
245245 } ) ;
246246 return ;
247247 }
248248
249- this . #dirClosed = true ;
249+ this . #closed = true ;
250250 const req = new FSReqCallback ( ) ;
251251 req . oncomplete = callback ;
252- this . #dirHandle . close ( req ) ;
252+ this . #handle . close ( req ) ;
253253 }
254254
255255 closeSync ( ) {
256- if ( this . #dirClosed === true ) {
256+ if ( this . #closed === true ) {
257257 throw new ERR_DIR_CLOSED ( ) ;
258258 }
259259
260- if ( this . #dirOperationQueue !== null ) {
260+ if ( this . #operationQueue !== null ) {
261261 throw new ERR_DIR_CONCURRENT_OPERATION ( ) ;
262262 }
263263
264- this . #dirClosed = true ;
265- const ctx = { path : this . #dirPath } ;
266- const result = this . #dirHandle . close ( undefined , ctx ) ;
264+ this . #closed = true ;
265+ const ctx = { path : this . #path } ;
266+ const result = this . #handle . close ( undefined , ctx ) ;
267267 handleErrorFromBinding ( ctx ) ;
268268 return result ;
269269 }
270270
271271 async * entries ( ) {
272272 try {
273273 while ( true ) {
274- const result = await this . #dirReadPromisified ( ) ;
274+ const result = await this . #readPromisified ( ) ;
275275 if ( result === null ) {
276276 break ;
277277 }
278278 yield result ;
279279 }
280280 } finally {
281- await this . #dirClosePromisified ( ) ;
281+ await this . #closePromisified ( ) ;
282282 }
283283 }
284284}
0 commit comments