1 # vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status](https://david-dm.org/wearefractal/vinyl.png?theme=shields.io)](https://david-dm.org/wearefractal/vinyl)
3 <table><br><tr><br><td>Package</td><td>vinyl</td><br></tr><br><tr><br><td>Description</td><br><td>A virtual file format</td><br></tr><br><tr><br><td>Node Version</td><br><td>>= 0.9</td><br></tr><br></table>
6 Read this for more info about how this plays into the grand scheme of things [https://medium.com/@eschoff/3828e8126466](https://medium.com/@eschoff/3828e8126466)
11 var File = require('vinyl');
13 var coffeeFile = new File({
16 path: "/test/file.coffee",
17 contents: new Buffer("test = 123")
22 When checking if an object is a vinyl file, you should not use instanceof. Use the isVinyl function instead.
25 var File = require('vinyl');
27 var dummy = new File({stuff});
30 File.isVinyl(dummy); // true
31 File.isVinyl(notAFile); // false
34 ### constructor(options)
36 Type: `String`<br><br>Default: `process.cwd()`
39 Used for relative pathing. Typically where a glob starts.
41 Type: `String`<br><br>Default: `options.cwd`
44 Full path to the file.
46 Type: `String`<br><br>Default: `undefined`
49 Path history. Has no effect if `options.path` is passed.
51 Type: `Array`<br><br>Default: `options.path ? [options.path] : []`
54 The result of an fs.stat call. See [fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats) for more information.
56 Type: `fs.Stats`<br><br>Default: `null`
61 Type: `Buffer, Stream, or null`<br><br>Default: `null`
64 Returns true if file.contents is a Buffer.
67 Returns true if file.contents is a Stream.
70 Returns true if file.contents is null.
73 Returns a new File object with all attributes cloned.<br>By default custom attributes are deep-cloned.
75 If opt or opt.deep is false, custom attributes will not be deep-cloned.
77 If opt.contents is false, it will copy file.contents Buffer's reference.
79 ### pipe(stream[, opt])
80 If file.contents is a Buffer, it will write it to the stream.
82 If file.contents is a Stream, it will pipe it to the stream.
84 If file.contents is null, it will do nothing.
86 If opt.end is false, the destination stream will not be ended (same as node core).
91 Returns a pretty String interpretation of the File. Useful for console.log.
94 The [Stream](https://nodejs.org/api/stream.html#stream_stream) or [Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer) of the file as it was passed in via options, or as the result of modification.
99 if (file.isBuffer()) {
100 console.log(file.contents.toString()); // logs out the string of contents
105 Absolute pathname string or `undefined`. Setting to a different value pushes the old value to `history`.
108 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`.
111 Returns path.relative for the file base and file path.
116 var file = new File({
119 path: "/test/file.coffee"
122 console.log(file.relative); // file.coffee
126 Gets and sets path.dirname for the file path.
131 var file = new File({
134 path: "/test/file.coffee"
137 console.log(file.dirname); // /test
139 file.dirname = '/specs';
141 console.log(file.dirname); // /specs
142 console.log(file.path); // /specs/file.coffee
147 Gets and sets path.basename for the file path.
152 var file = new File({
155 path: "/test/file.coffee"
158 console.log(file.basename); // file.coffee
160 file.basename = 'file.js';
162 console.log(file.basename); // file.js
163 console.log(file.path); // /test/file.js
168 Gets and sets path.extname for the file path.
173 var file = new File({
176 path: "/test/file.coffee"
179 console.log(file.extname); // .coffee
181 file.extname = '.js';
183 console.log(file.extname); // .js
184 console.log(file.path); // /test/file.js
188 [npm-url]: https://npmjs.org/package/vinyl
189 [npm-image]: https://badge.fury.io/js/vinyl.png
190 [travis-url]: https://travis-ci.org/wearefractal/vinyl
191 [travis-image]: https://travis-ci.org/wearefractal/vinyl.png?branch=master
192 [coveralls-url]: https://coveralls.io/r/wearefractal/vinyl
193 [coveralls-image]: https://coveralls.io/repos/wearefractal/vinyl/badge.png
194 [depstat-url]: https://david-dm.org/wearefractal/vinyl
195 [depstat-image]: https://david-dm.org/wearefractal/vinyl.png