time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (1613B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2019 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var op = require( 'fs' ).open;
     24 var defaults = require( './defaults.json' );
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Asynchronously opens a file.
     31 *
     32 * @param {(string|Buffer)} path - file path
     33 * @param {(string|number)} [flags='r'] - file system flags
     34 * @param {integer} [mode=0o666] - file mode
     35 * @param {Function} clbk - callback to invoke after opening a file
     36 * @returns {void}
     37 *
     38 * @example
     39 * var closeSync = require( '@stdlib/fs/close' ).sync;
     40 * var open = require( '@stdlib/fs/open' );
     41 *
     42 * function onOpen( error, fd ) {
     43 *     if ( error ) {
     44 *         throw error;
     45 *     }
     46 *     closeSync( fd );
     47 * }
     48 * open( __filename, onOpen );
     49 */
     50 function open( path, flags, mode, clbk ) { // eslint-disable-line stdlib/no-redeclare
     51 	var nargs = arguments.length;
     52 	if ( nargs === 2 ) {
     53 		return op( path, defaults.flags, defaults.mode, flags );
     54 	}
     55 	if ( nargs === 3 ) {
     56 		return op( path, flags, defaults.mode, mode );
     57 	}
     58 	op( path, flags, mode, clbk );
     59 }
     60 
     61 
     62 // EXPORTS //
     63 
     64 module.exports = open;