aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vinyl-fs/lib/src/getContents
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/vinyl-fs/lib/src/getContents')
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/bufferFile.js22
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/index.js31
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/readDir.js8
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js18
-rw-r--r--node_modules/vinyl-fs/lib/src/getContents/streamFile.js26
5 files changed, 105 insertions, 0 deletions
diff --git a/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js b/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
new file mode 100644
index 000000000..894dd9cea
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var fs = require('graceful-fs');
+var stripBom = require('strip-bom');
+
+function bufferFile(file, opt, cb) {
+ fs.readFile(file.path, function(err, data) {
+ if (err) {
+ return cb(err);
+ }
+
+ if (opt.stripBOM) {
+ file.contents = stripBom(data);
+ } else {
+ file.contents = data;
+ }
+
+ cb(null, file);
+ });
+}
+
+module.exports = bufferFile;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/index.js b/node_modules/vinyl-fs/lib/src/getContents/index.js
new file mode 100644
index 000000000..c1c8c159d
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/index.js
@@ -0,0 +1,31 @@
+'use strict';
+
+var through2 = require('through2');
+var readDir = require('./readDir');
+var readSymbolicLink = require('./readSymbolicLink');
+var bufferFile = require('./bufferFile');
+var streamFile = require('./streamFile');
+
+function getContents(opt) {
+ return through2.obj(opt, function(file, enc, cb) {
+ // Don't fail to read a directory
+ if (file.isDirectory()) {
+ return readDir(file, opt, cb);
+ }
+
+ // Process symbolic links included with `followSymlinks` option
+ if (file.stat && file.stat.isSymbolicLink()) {
+ return readSymbolicLink(file, opt, cb);
+ }
+
+ // Read and pass full contents
+ if (opt.buffer !== false) {
+ return bufferFile(file, opt, cb);
+ }
+
+ // Don't buffer anything - just pass streams
+ return streamFile(file, opt, cb);
+ });
+}
+
+module.exports = getContents;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/readDir.js b/node_modules/vinyl-fs/lib/src/getContents/readDir.js
new file mode 100644
index 000000000..a800d4738
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/readDir.js
@@ -0,0 +1,8 @@
+'use strict';
+
+function readDir(file, opt, cb) {
+ // Do nothing for now
+ cb(null, file);
+}
+
+module.exports = readDir;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js b/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js
new file mode 100644
index 000000000..794077a62
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/readSymbolicLink.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var fs = require('graceful-fs');
+
+function readLink(file, opt, cb) {
+ fs.readlink(file.path, function(err, target) {
+ if (err) {
+ return cb(err);
+ }
+
+ // Store the link target path
+ file.symlink = target;
+
+ return cb(null, file);
+ });
+}
+
+module.exports = readLink;
diff --git a/node_modules/vinyl-fs/lib/src/getContents/streamFile.js b/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
new file mode 100644
index 000000000..43dc12635
--- /dev/null
+++ b/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
@@ -0,0 +1,26 @@
+'use strict';
+
+var fs = require('graceful-fs');
+var stripBom = require('strip-bom-stream');
+var lazystream = require('lazystream');
+
+function streamFile(file, opt, cb) {
+ if (typeof opt === 'function') {
+ cb = opt;
+ opt = {};
+ }
+
+ var filePath = file.path;
+
+ file.contents = new lazystream.Readable(function() {
+ return fs.createReadStream(filePath);
+ });
+
+ if (opt.stripBOM) {
+ file.contents = file.contents.pipe(stripBom());
+ }
+
+ cb(null, file);
+}
+
+module.exports = streamFile;