From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/shelljs/src/head.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'node_modules/shelljs/src/head.js') diff --git a/node_modules/shelljs/src/head.js b/node_modules/shelljs/src/head.js index 13d582977..e112e49e1 100644 --- a/node_modules/shelljs/src/head.js +++ b/node_modules/shelljs/src/head.js @@ -10,9 +10,9 @@ common.register('head', _head, { // This reads n or more lines, or the entire file, whichever is less. function readSomeLines(file, numLines) { - var BUF_LENGTH = 64 * 1024; - var buf = new Buffer(BUF_LENGTH); - var bytesRead = BUF_LENGTH; + var buf = common.buffer(); + var bufLength = buf.length; + var bytesRead = bufLength; var pos = 0; var fdr = null; @@ -24,8 +24,8 @@ function readSomeLines(file, numLines) { var numLinesRead = 0; var ret = ''; - while (bytesRead === BUF_LENGTH && numLinesRead < numLines) { - bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos); + while (bytesRead === bufLength && numLinesRead < numLines) { + bytesRead = fs.readSync(fdr, buf, 0, bufLength, pos); var bufStr = buf.toString('utf8', 0, bytesRead); numLinesRead += bufStr.split('\n').length - 1; ret += bufStr; @@ -72,9 +72,16 @@ function _head(options, files) { var shouldAppendNewline = false; files.forEach(function (file) { - if (!fs.existsSync(file) && file !== '-') { - common.error('no such file or directory: ' + file, { continue: true }); - return; + if (file !== '-') { + if (!fs.existsSync(file)) { + common.error('no such file or directory: ' + file, { continue: true }); + return; + } else if (fs.statSync(file).isDirectory()) { + common.error("error reading '" + file + "': Is a directory", { + continue: true, + }); + return; + } } var contents; -- cgit v1.2.3