repl.txt (1696B)
1 2 {{alias}}( path[, flags[, mode]], clbk ) 3 Asynchronously opens a file. 4 5 Some characters, such as <>:"/\|?*, are reserved under Windows. 6 Under NTFS, if the path contains a colon, Node.js will open a file system 7 stream. 8 9 Parameters 10 ---------- 11 path: string|Buffer 12 Filename. 13 14 flags: string|number (optional) 15 File system flags. Default: 'r'. 16 17 mode: integer (optional) 18 File mode (permission and sticky bits). This sets the file mode, but 19 only if the file was created. On Windows, only the write permission can 20 be manipulated. Default: 0o666. 21 22 clbk: Function 23 Callback to invoke upon opening a file. 24 25 Examples 26 -------- 27 > function onOpen( error, fd ) { 28 ... if ( error ) { 29 ... console.error( error.message ); 30 ... } else { 31 ... {{alias:@stdlib/fs/close}}.sync( fd ); 32 ... } 33 ... }; 34 > {{alias}}( './beep/boop.txt', onOpen ); 35 36 37 {{alias}}.sync( path[, flags[, mode]] ) 38 Synchronously opens a file. 39 40 Parameters 41 ---------- 42 path: string|Buffer 43 Filename. 44 45 flags: string|number (optional) 46 File system flags. Default: 'r'. 47 48 mode: integer (optional) 49 File mode (permission and sticky bits). This sets the file mode, but 50 only if the file was created. On Windows, only the write permission can 51 be manipulated. Default: 0o666. 52 53 Returns 54 ------- 55 fd: Error|integer 56 File descriptor. 57 58 Examples 59 -------- 60 > var fd = {{alias}}.sync( './beep/boop.txt' ); 61 > if ( !{{alias:@stdlib/assert/is-error}}( fd ) ) { {{alias:@stdlib/fs/close}}.sync( fd ); }; 62 63 See Also 64 -------- 65