Code coverage report for master/node/fs.js

Statements: 25% (9 / 36)      Branches: 0% (0 / 6)      Functions: 25% (1 / 4)      Lines: 25% (9 / 36)      Ignored: none     

All files » master/node/ » fs.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64    1 1 1 1   1                                     1                 1                                                 1 82    
'use strict';
 
var fs = require('fs');
var path = require('path');
var stream = require('stream');
var wrench = require('wrench');
 
var toDir = exports.toDir = function(_path) {
    var isDirectory;
 
    _path = path.normalize(_path);
 
    try {
        isDirectory = fs.statSync(_path).isDirectory();
    }
    catch(e) {
        isDirectory = false;
    }
 
    if (isDirectory) {
       return _path;
    } else {
        return path.dirname(_path);
    }
};
 
exports.mkPath = function(/**Array*/ _path) {
    if ( Array.isArray(_path) ) {
        _path = _path.join('');
    }
 
    wrench.mkdirSyncRecursive(_path);
};
 
// adapted from http://procbits.com/2011/11/15/synchronous-file-copy-in-node-js
exports.copyFileSync = function(inFile, outDir, fileName) {
    var BUF_LENGTH = 64 * 1024;
 
    var read;
    var write;
 
    var buffer = new Buffer(BUF_LENGTH);
    var bytesRead = 1;
    var outFile = path.join( outDir, fileName || path.basename(inFile) );
    var pos = 0;
 
    wrench.mkdirSyncRecursive(outDir);
    read = fs.openSync(inFile, 'r');
    write = fs.openSync(outFile, 'w');
 
    while (bytesRead > 0) {
        bytesRead = fs.readSync(read, buffer, 0, BUF_LENGTH, pos);
        fs.writeSync(write, buffer, 0, bytesRead);
        pos += bytesRead;
    }
 
    fs.closeSync(read);
    return fs.closeSync(write);
};
 
Object.keys(fs).forEach(function(key) {
    exports[key] = fs[key];
});