@@ -23,7 +23,7 @@ const utils = new Utils(llfs);
2323const { log, success, error, warn } = $$ . logger ;
2424
2525module . exports = {
26- readdir ( path , options = ( ) => { } , callback = options ) {
26+ readdir ( path , options = ( ) => { } , callback = options ) {
2727 let resolved = null ;
2828
2929 if ( utils . isSystemPath ( path ) ) {
@@ -80,10 +80,10 @@ module.exports = {
8080 return filesystem . readdir ( resolved . parts . slice ( 2 ) . join ( '/' ) , callback ) ;
8181 } )
8282
83- /* .then(list => {
84- if (resolved.level <= 1) return;
85- callback(null, list.map(file => file.name), list);
86- })*/
83+ /* .then(list => {
84+ if (resolved.level <= 1) return;
85+ callback(null, list.map(file => file.name), list);
86+ })*/
8787 . catch ( ( err ) => {
8888 callback ( err ) ;
8989 } ) ;
@@ -95,17 +95,24 @@ module.exports = {
9595 * @param {object } [options] - Options
9696 * @param {function } callback - Callback(error, result)
9797 */
98- readFile ( path , options = ( ) => { } , callback = options ) {
98+ readFile ( path , options = ( ) => { } , callback = options ) {
9999 let resolved = null ;
100100
101+ const encoding = typeof options === 'string'
102+ ? options
103+ : 'buffer' ;
104+
101105 if ( utils . isSystemPath ( path ) ) {
102106 log ( `${ path } is a system path` , { level : 'fs' } ) ;
103107
104108 const extpath = utils . extractSystemPath ( path ) ;
105109
106110 log ( `${ path } extracted to ${ extpath } ` , { level : 'fs' } ) ;
107111
108- callback ( null , __SYSCALL . initrdReadFileBuffer ( extpath ) ) ;
112+ if ( encoding === 'buffer' )
113+ callback ( null , Buffer . from ( __SYSCALL . initrdReadFileBuffer ( extpath ) ) ) ;
114+ else
115+ callback ( null , Buffer . from ( __SYSCALL . initrdReadFileBuffer ( extpath ) ) . toString ( encoding ) ) ;
109116 success ( 'OK!' , { from : 'FS->readFile->System' , level : 'fs' } ) ;
110117
111118 return ;
@@ -133,11 +140,10 @@ module.exports = {
133140
134141 /** Returns file content (or buffer if encoding = 'buffer')
135142 * @param {string } path - Path to file
136- * @param {string } [encoding='ascii '] - File encoding
143+ * @param {string } [encoding='buffer '] - File encoding
137144 * @returns {string } or Buffer
138145 */
139- readFileSync ( path , encoding = 'ascii' ) {
140- // TODO: buffer => binary
146+ readFileSync ( path , encoding = 'buffer' ) {
141147 if ( utils . isSystemPath ( path ) ) {
142148 log ( `${ path } is a system path` , { level : 'fs' } ) ;
143149
@@ -147,17 +153,19 @@ module.exports = {
147153
148154 success ( 'OK!' , { from : 'FS->readFile->System' , level : 'fs' } ) ;
149155
156+ const buffer = Buffer . from ( __SYSCALL . initrdReadFileBuffer ( extpath ) ) ;
157+
150158 return encoding === 'buffer'
151- ? __SYSCALL . initrdReadFileBuffer ( extpath )
152- : __SYSCALL . initrdReadFile ( extpath ) ;
159+ ? buffer
160+ : buffer . toString ( encoding ) ;
153161 }
154162
155- warn ( 'readFileSync for external pathes doesn\'t implemented!' , { from : 'fs->readFileSync' } ) ;
163+ warn ( 'readFileSync for external pathes doesn\'t implemented! Use readFile. ' , { from : 'fs->readFileSync' } ) ;
156164
157- return '' ; // TODO:
165+ return new Buffer ( 0 ) ; // TODO:
158166 } ,
159167
160- writeFile ( path , data , options = ( ) => { } , callback = options ) {
168+ writeFile ( path , data , options = ( ) => { } , callback = options ) {
161169 let resolved = null ;
162170
163171 try {
@@ -179,7 +187,8 @@ module.exports = {
179187 callback ( new Error ( 'Is a directory' ) ) ;
180188 }
181189 } ,
182- mkdir ( path , options = ( ) => { } , callback = options ) {
190+
191+ mkdir ( path , options = ( ) => { } , callback = options ) {
183192 let resolved = null ;
184193
185194 try {
0 commit comments