repl.txt (1619B)
1 2 {{alias}}( file[, options], clbk ) 3 Asynchronously reads the entire contents of a file. 4 5 If provided an encoding, the function returns a string. Otherwise, the 6 function returns a Buffer object. 7 8 Parameters 9 ---------- 10 file: string|Buffer|integer 11 Filename or file descriptor. 12 13 options: Object|string (optional) 14 Options. If a string, the value is the encoding. 15 16 options.encoding: string|null (optional) 17 Encoding. Default: null. 18 19 options.flag: string (optional) 20 Flag. Default: 'r'. 21 22 clbk: Function 23 Callback to invoke upon reading file contents. 24 25 Examples 26 -------- 27 > function onRead( error, data ) { 28 ... if ( error ) { 29 ... console.error( error.message ); 30 ... } else { 31 ... console.log( data ); 32 ... } 33 ... }; 34 > {{alias}}( './beep/boop.js', onRead ); 35 36 37 {{alias}}.sync( file[, options] ) 38 Synchronously reads the entire contents of a file. 39 40 If provided an encoding, the function returns a string. Otherwise, the 41 function returns a Buffer object. 42 43 Parameters 44 ---------- 45 file: string|Buffer|integer 46 Filename or file descriptor. 47 48 options: Object|string (optional) 49 Options. If a string, the value is the encoding. 50 51 options.encoding: string|null (optional) 52 Encoding. Default: null. 53 54 options.flag: string (optional) 55 Flag. Default: 'r'. 56 57 Returns 58 ------- 59 out: Error|Buffer|string 60 File contents. 61 62 Examples 63 -------- 64 > var out = {{alias}}.sync( './beep/boop.js' ); 65 66 See Also 67 -------- 68