1
- import { resolve as resolveCrossPlatform } from 'path' ;
2
1
import * as pathModule from 'path' ;
3
2
import { Node , Link , File } from './node' ;
4
3
import Stats from './Stats' ;
@@ -16,6 +15,7 @@ import extend = require('fast-extend');
16
15
import util = require( 'util' ) ;
17
16
import createPromisesApi from './promises' ;
18
17
18
+ const resolveCrossPlatform = pathModule . resolve ;
19
19
const {
20
20
O_RDONLY ,
21
21
O_WRONLY ,
@@ -30,7 +30,8 @@ const {
30
30
COPYFILE_FICLONE_FORCE ,
31
31
} = constants ;
32
32
33
- let sep , relative ;
33
+ let sep ;
34
+ let relative ;
34
35
if ( pathModule . posix ) {
35
36
const { posix } = pathModule ;
36
37
@@ -214,7 +215,7 @@ function getOptions<T extends IOptions>(defaults: T, options?: T | string): T {
214
215
let opts : T ;
215
216
if ( ! options ) return defaults ;
216
217
else {
217
- var tipeof = typeof options ;
218
+ const tipeof = typeof options ;
218
219
switch ( tipeof ) {
219
220
case 'string' :
220
221
opts = extend ( { } , defaults , { encoding : options as string } ) ;
@@ -362,10 +363,10 @@ function getPathFromURLPosix(url) {
362
363
if ( url . hostname !== '' ) {
363
364
return new errors . TypeError ( 'ERR_INVALID_FILE_URL_HOST' , process . platform ) ;
364
365
}
365
- let pathname = url . pathname ;
366
+ const pathname = url . pathname ;
366
367
for ( let n = 0 ; n < pathname . length ; n ++ ) {
367
368
if ( pathname [ n ] === '%' ) {
368
- let third = pathname . codePointAt ( n + 2 ) | 0x20 ;
369
+ const third = pathname . codePointAt ( n + 2 ) | 0x20 ;
369
370
if ( pathname [ n + 1 ] === '2' && third === 102 ) {
370
371
return new errors . TypeError ( 'ERR_INVALID_FILE_URL_PATH' , 'must not include encoded / characters' ) ;
371
372
}
@@ -462,6 +463,7 @@ function validateFd(fd) {
462
463
// converts Date or number to a fractional UNIX timestamp
463
464
export function toUnixTimestamp ( time ) {
464
465
if ( typeof time === 'string' && + time == ( time as any ) ) {
466
+ // tslint:disable-line triple-equals
465
467
return + time ;
466
468
}
467
469
if ( time instanceof Date ) {
@@ -578,7 +580,7 @@ export class Volume {
578
580
const root = this . createLink ( ) ;
579
581
root . setNode ( this . createNode ( true ) ) ;
580
582
581
- const self = this ;
583
+ const self = this ; // tslint:disable-line no-this-assignment
582
584
583
585
this . StatWatcher = class extends StatWatcher {
584
586
constructor ( ) {
@@ -688,7 +690,7 @@ export class Volume {
688
690
let link = this . root ;
689
691
let i = 0 ;
690
692
while ( i < steps . length ) {
691
- let step = steps [ i ] ;
693
+ const step = steps [ i ] ;
692
694
link = link . getChild ( step ) ;
693
695
if ( ! link ) return null ;
694
696
@@ -708,7 +710,7 @@ export class Volume {
708
710
709
711
// Just like `getLinkOrThrow`, but also dereference/resolves symbolic links.
710
712
getResolvedLinkOrThrow ( filename : string , funcName ?: string ) : Link {
711
- let link = this . getResolvedLink ( filename ) ;
713
+ const link = this . getResolvedLink ( filename ) ;
712
714
if ( ! link ) throwError ( ENOENT , funcName , filename ) ;
713
715
return link ;
714
716
}
@@ -793,11 +795,11 @@ export class Volume {
793
795
private _toJSON ( link = this . root , json = { } , path ?: string ) {
794
796
let isEmpty = true ;
795
797
796
- for ( let name in link . children ) {
798
+ for ( const name in link . children ) {
797
799
isEmpty = false ;
798
800
799
- let child = link . getChild ( name ) ;
800
- let node = child . getNode ( ) ;
801
+ const child = link . getChild ( name ) ;
802
+ const node = child . getNode ( ) ;
801
803
if ( node . isFile ( ) ) {
802
804
let filename = child . getPath ( ) ;
803
805
if ( path ) filename = relative ( path , filename ) ;
@@ -819,11 +821,11 @@ export class Volume {
819
821
}
820
822
821
823
toJSON ( paths ?: TFilePath | TFilePath [ ] , json = { } , isRelative = false ) {
822
- let links : Link [ ] = [ ] ;
824
+ const links : Link [ ] = [ ] ;
823
825
824
826
if ( paths ) {
825
827
if ( ! ( paths instanceof Array ) ) paths = [ paths ] ;
826
- for ( let path of paths ) {
828
+ for ( const path of paths ) {
827
829
const filename = pathToFilename ( path ) ;
828
830
const link = this . getResolvedLink ( filename ) ;
829
831
if ( ! link ) continue ;
@@ -834,7 +836,7 @@ export class Volume {
834
836
}
835
837
836
838
if ( ! links . length ) return json ;
837
- for ( let link of links ) this . _toJSON ( link , json , isRelative ? link . getPath ( ) : '' ) ;
839
+ for ( const link of links ) this . _toJSON ( link , json , isRelative ? link . getPath ( ) : '' ) ;
838
840
return json ;
839
841
}
840
842
@@ -1011,7 +1013,7 @@ export class Volume {
1011
1013
// This `if` branch is from Node.js
1012
1014
if ( length === 0 ) {
1013
1015
return process . nextTick ( ( ) => {
1014
- callback && callback ( null , 0 , buffer ) ;
1016
+ if ( callback ) callback ( null , 0 , buffer ) ;
1015
1017
} ) ;
1016
1018
}
1017
1019
@@ -1029,7 +1031,7 @@ export class Volume {
1029
1031
let result : Buffer | string ;
1030
1032
1031
1033
const isUserFd = typeof id === 'number' ;
1032
- let userOwnsFd : boolean = isUserFd && isFd ( id ) ;
1034
+ const userOwnsFd : boolean = isUserFd && isFd ( id ) ;
1033
1035
let fd : number ;
1034
1036
1035
1037
if ( userOwnsFd ) fd = id as number ;
@@ -1211,7 +1213,7 @@ export class Volume {
1211
1213
let position = flagsNum & O_APPEND ? null : 0 ;
1212
1214
try {
1213
1215
while ( length > 0 ) {
1214
- let written = this . writeSync ( fd , buf , offset , length , position ) ;
1216
+ const written = this . writeSync ( fd , buf , offset , length , position ) ;
1215
1217
offset += written ;
1216
1218
length -= written ;
1217
1219
if ( position !== null ) position += written ;
@@ -1585,7 +1587,7 @@ export class Volume {
1585
1587
1586
1588
if ( options . withFileTypes ) {
1587
1589
const list : Dirent [ ] = [ ] ;
1588
- for ( let name in link . children ) {
1590
+ for ( const name in link . children ) {
1589
1591
list . push ( Dirent . build ( link . children [ name ] , options . encoding ) ) ;
1590
1592
}
1591
1593
if ( ! isWin && options . encoding !== 'buffer' )
@@ -1598,7 +1600,7 @@ export class Volume {
1598
1600
}
1599
1601
1600
1602
const list : TDataOut [ ] = [ ] ;
1601
- for ( let name in link . children ) {
1603
+ for ( const name in link . children ) {
1602
1604
list . push ( strToEncoding ( name , options . encoding ) ) ;
1603
1605
}
1604
1606
@@ -1807,7 +1809,7 @@ export class Volume {
1807
1809
}
1808
1810
1809
1811
private mkdtempBase ( prefix : string , encoding : TEncodingExtended , retry : number = 5 ) : TDataOut {
1810
- let filename = prefix + this . genRndStr ( ) ;
1812
+ const filename = prefix + this . genRndStr ( ) ;
1811
1813
try {
1812
1814
this . mkdirBase ( filename , MODE . DIR ) ;
1813
1815
return strToEncoding ( filename , encoding ) ;
@@ -2051,6 +2053,7 @@ export class Volume {
2051
2053
options = null ;
2052
2054
}
2053
2055
2056
+ // tslint:disable-next-line prefer-const
2054
2057
let { persistent, recursive, encoding } : IWatchOptions = getDefaultOpts ( options ) ;
2055
2058
if ( persistent === undefined ) persistent = true ;
2056
2059
if ( recursive === undefined ) recursive = false ;
@@ -2120,6 +2123,7 @@ export class StatWatcher extends EventEmitter {
2120
2123
}
2121
2124
}
2122
2125
2126
+ /* tslint:disable no-var-keyword prefer-const */
2123
2127
// ---------------------------------------- ReadStream
2124
2128
2125
2129
export interface IReadStream extends Readable {
@@ -2188,8 +2192,8 @@ function FsReadStream(vol, path, options) {
2188
2192
}
2189
2193
2190
2194
FsReadStream . prototype . open = function ( ) {
2191
- var self = this ;
2192
- this . _vol . open ( this . path , this . flags , this . mode , function ( er , fd ) {
2195
+ var self = this ; // tslint:disable-line no-this-assignment
2196
+ this . _vol . open ( this . path , this . flags , this . mode , ( er , fd ) => {
2193
2197
if ( er ) {
2194
2198
if ( self . autoClose ) {
2195
2199
if ( self . destroy ) self . destroy ( ) ;
@@ -2233,7 +2237,7 @@ FsReadStream.prototype._read = function(n) {
2233
2237
if ( toRead <= 0 ) return this . push ( null ) ;
2234
2238
2235
2239
// the actual read.
2236
- var self = this ;
2240
+ var self = this ; // tslint:disable-line no-this-assignment
2237
2241
this . _vol . read ( this . fd , pool , pool . used , toRead , this . pos , onread ) ;
2238
2242
2239
2243
// move the pool positions, and internal position for reading.
@@ -2259,7 +2263,7 @@ FsReadStream.prototype._read = function(n) {
2259
2263
} ;
2260
2264
2261
2265
FsReadStream . prototype . _destroy = function ( err , cb ) {
2262
- this . close ( function ( err2 ) {
2266
+ this . close ( err2 => {
2263
2267
cb ( err || err2 ) ;
2264
2268
} ) ;
2265
2269
} ;
@@ -2373,8 +2377,8 @@ FsWriteStream.prototype._write = function(data, encoding, cb) {
2373
2377
} ) ;
2374
2378
}
2375
2379
2376
- var self = this ;
2377
- this . _vol . write ( this . fd , data , 0 , data . length , this . pos , function ( er , bytes ) {
2380
+ var self = this ; // tslint:disable-line no-this-assignment
2381
+ this . _vol . write ( this . fd , data , 0 , data . length , this . pos , ( er , bytes ) => {
2378
2382
if ( er ) {
2379
2383
if ( self . autoClose && self . destroy ) {
2380
2384
self . destroy ( ) ;
@@ -2395,7 +2399,7 @@ FsWriteStream.prototype._writev = function(data, cb) {
2395
2399
} ) ;
2396
2400
}
2397
2401
2398
- const self = this ;
2402
+ const self = this ; // tslint:disable-line no-this-assignment
2399
2403
const len = data . length ;
2400
2404
const chunks = new Array ( len ) ;
2401
2405
var size = 0 ;
0 commit comments