repl.txt (2024B)
1 2 {{alias}}( filepaths[, options], clbk ) 3 Asynchronously reads the entire contents of each file in a file list. 4 5 If a provided an encoding, the function returns file contents as strings. 6 Otherwise, the function returns Buffer objects. 7 8 Each file is represented by an object with the following fields: 9 10 - file: file path 11 - data: file contents as either a Buffer or string 12 13 Parameters 14 ---------- 15 filepaths: Array<string> 16 Filepaths. 17 18 options: Object|string (optional) 19 Options. If a string, the value is the encoding. 20 21 options.encoding: string|null (optional) 22 Encoding. Default: null. 23 24 options.flag: string (optional) 25 Flag. Default: 'r'. 26 27 clbk: Function 28 Callback to invoke upon reading file contents. 29 30 Examples 31 -------- 32 > function onRead( error, data ) { 33 ... if ( error ) { 34 ... console.error( error.message ); 35 ... } else { 36 ... console.log( data ); 37 ... } 38 ... }; 39 > var filepaths = [ './beep/boop.txt', './foo/bar.txt' ]; 40 > {{alias}}( filepaths, onRead ); 41 42 43 {{alias}}.sync( filepaths[, options] ) 44 Synchronously reads the entire contents of each file in a file list. 45 46 If a provided an encoding, the function returns file contents as strings. 47 Otherwise, the function returns Buffer objects. 48 49 Parameters 50 ---------- 51 filepaths: Array<string> 52 Filepaths. 53 54 options: Object|string (optional) 55 Options. If a string, the value is the encoding. 56 57 options.encoding: string|null (optional) 58 Encoding. Default: null. 59 60 options.flag: string (optional) 61 Flag. Default: 'r'. 62 63 Returns 64 ------- 65 out: Error|Array|Array<string> 66 File contents. 67 68 out[ i ].file: string 69 File path. 70 71 out[ i ].data: Buffer|string 72 File contents. 73 74 Examples 75 -------- 76 > var filepaths = [ './beep/boop.txt', './foo/bar.txt' ]; 77 > var out = {{alias}}.sync( filepaths ); 78 79 See Also 80 -------- 81