Bachir Soussi Chiadmi ac58a24f5c added bower, gulp | 7 years ago | |
---|---|---|
.. | ||
lib | 7 years ago | |
LICENSE | 7 years ago | |
README.md | 7 years ago | |
index.js | 7 years ago | |
package.json | 7 years ago |
Package | vinyl |
Description | A virtual file format |
Node Version | >= 0.9 |
Read this for more info about how this plays into the grand scheme of things https://medium.com/@eschoff/3828e8126466
var File = require('vinyl');
var coffeeFile = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee",
contents: new Buffer("test = 123")
});
When checking if an object is a vinyl file, you should not use instanceof. Use the isVinyl function instead.
var File = require('vinyl');
var dummy = new File({stuff});
var notAFile = {};
File.isVinyl(dummy); // true
File.isVinyl(notAFile); // false
Type: String
Default: process.cwd()
Used for relative pathing. Typically where a glob starts.
Type: String
Default: options.cwd
Full path to the file.
Type: String
Default: undefined
Path history. Has no effect if options.path
is passed.
Type: Array
Default: options.path ? [options.path] : []
The result of an fs.stat call. See fs.Stats for more information.
Type: fs.Stats
Default: null
File contents.
Type: Buffer, Stream, or null
Default: null
Returns true if file.contents is a Buffer.
Returns true if file.contents is a Stream.
Returns true if file.contents is null.
Returns a new File object with all attributes cloned.
By default custom attributes are deep-cloned.
If opt or opt.deep is false, custom attributes will not be deep-cloned.
If opt.contents is false, it will copy file.contents Buffer's reference.
If file.contents is a Buffer, it will write it to the stream.
If file.contents is a Stream, it will pipe it to the stream.
If file.contents is null, it will do nothing.
If opt.end is false, the destination stream will not be ended (same as node core).
Returns the stream.
Returns a pretty String interpretation of the File. Useful for console.log.
The Stream or Buffer of the file as it was passed in via options, or as the result of modification.
For example:
if (file.isBuffer()) {
console.log(file.contents.toString()); // logs out the string of contents
}
Absolute pathname string or undefined
. Setting to a different value pushes the old value to history
.
Array of path
values the file object has had, from history[0]
(original) through history[history.length - 1]
(current). history
and its elements should normally be treated as read-only and only altered indirectly by setting path
.
Returns path.relative for the file base and file path.
Example:
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.relative); // file.coffee
Gets and sets path.dirname for the file path.
Example:
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.dirname); // /test
file.dirname = '/specs';
console.log(file.dirname); // /specs
console.log(file.path); // /specs/file.coffee
`
Gets and sets path.basename for the file path.
Example:
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.basename); // file.coffee
file.basename = 'file.js';
console.log(file.basename); // file.js
console.log(file.path); // /test/file.js
`
Gets and sets path.extname for the file path.
Example:
var file = new File({
cwd: "/",
base: "/test/",
path: "/test/file.coffee"
});
console.log(file.extname); // .coffee
file.extname = '.js';
console.log(file.extname); // .js
console.log(file.path); // /test/file.js
`