@@ -29,7 +29,9 @@ function linuxOsInfo (opts) {
2929 let mode = 'promise'
3030 opts = opts || { }
3131
32- const list = opts . list || defaultList
32+
33+
34+ const list = Array . isArray ( opts . list ) ? opts . list : defaultList
3335
3436 if ( typeof opts . mode === 'function' ) {
3537 mode = 'callback'
@@ -75,30 +77,29 @@ function linuxOsInfo (opts) {
7577 function asynchronousRead ( resolve , reject ) {
7678 let i = 0
7779
78- function tryRead ( file ) {
79- fs . readFile ( file , 'utf8' , ( err , data ) => {
80- if ( err ) {
81- i += 1
82- if ( i >= list . length ) {
83- const e = new Error ( 'linux-os-info - no file found' )
84- outputData . file = e
85- mode === 'promise' ? resolve ( outputData ) : opts . mode ( null , outputData )
80+ function tryRead ( ) {
81+ if ( i >= list . length ) {
82+ const e = new Error ( 'linux-os-info - no file found' )
83+ outputData . file = e
84+ mode === 'promise' ? resolve ( outputData ) : opts . mode ( null , outputData )
85+ } else {
86+ // try to read the file.
87+ let file = list [ i ] . path
88+ fs . readFile ( file , 'utf8' , ( err , data ) => {
89+ if ( err ) {
90+ i += 1
91+ tryRead ( )
8692 } else {
87- tryRead ( list [ i ] . path )
93+ list [ i ] . parser ( data , outputData )
94+ outputData . file = file
95+ mode === 'promise' ? resolve ( outputData ) : opts . mode ( null , outputData )
8896 }
89- } else {
90- list [ i ] . parser ( data , outputData )
91- outputData . file = file
92- mode === 'promise' ? resolve ( outputData ) : opts . mode ( null , outputData )
93- // don't queue up another read.
94- return
95- }
96- } )
97+ } )
98+ }
9799 }
98100
99- tryRead ( list [ i ] . path )
101+ tryRead ( )
100102 }
101-
102103}
103104
104105//
0 commit comments