aboutsummaryrefslogtreecommitdiff
path: root/node_modules/shelljs/src/head.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/shelljs/src/head.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
downloadwallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz
node_modules
Diffstat (limited to 'node_modules/shelljs/src/head.js')
-rw-r--r--node_modules/shelljs/src/head.js23
1 files changed, 15 insertions, 8 deletions
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;