Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vinyl-file

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinyl-file - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

57

index.js

@@ -7,3 +7,10 @@ 'use strict';

exports.read = function (pth, cb) {
exports.read = function (pth, opts, cb) {
opts = opts || {};
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
fs.stat(pth, function (err, stat) {

@@ -15,2 +22,23 @@ if (err) {

var cwd = opts.cwd || process.cwd();
var base = opts.base || cwd;
var file = new File({
cwd: cwd,
base: base,
path: path.resolve(pth),
stat: stat,
});
if (opts.read === false) {
cb(null, file);
return;
}
if (opts.buffer === false) {
file.contents = fs.createReadStream(pth).pipe(stripBom.stream());
cb(null, file);
return;
}
fs.readFile(pth, function (err, buf) {

@@ -22,9 +50,4 @@ if (err) {

cb(null, new File({
cwd: process.cwd(),
base: process.cwd(),
path: path.resolve(pth),
stat: stat,
contents: stripBom(buf)
}));
file.contents = stripBom(buf);
cb(null, file);
});

@@ -34,10 +57,20 @@ });

exports.readSync = function (pth) {
exports.readSync = function (pth, opts) {
opts = opts || {};
var contents;
if (opts.read !== false) {
contents = opts.buffer === false ?
fs.createReadStream(pth).pipe(stripBom.stream()) :
stripBom(fs.readFileSync(pth));
}
return new File({
cwd: process.cwd(),
base: process.cwd(),
cwd: opts.cwd || process.cwd(),
base: opts.base || process.cwd(),
path: path.resolve(pth),
stat: fs.statSync(pth),
contents: stripBom(fs.readFileSync(pth))
contents: contents
});
};
{
"name": "vinyl-file",
"version": "1.0.0",
"version": "1.1.0",
"description": "Create a vinyl file from an actual file",

@@ -27,3 +27,5 @@ "license": "MIT",

"virtual",
"format"
"format",
"gulp",
"gulpfriendly"
],

@@ -36,4 +38,5 @@ "dependencies": {

"devDependencies": {
"ava": "0.0.4"
"ava": "0.0.4",
"isstream": "^0.1.0"
}
}

@@ -28,4 +28,45 @@ # vinyl-file [![Build Status](https://travis-ci.org/sindresorhus/vinyl-file.svg?branch=master)](https://travis-ci.org/sindresorhus/vinyl-file)

## API
### read(path, [options], callback)
Create a vinyl file and pass it to the callback.
### readSync(path, [options])
Create a vinyl file synchronously and return it.
#### options
##### base
Type: `string`
Default: `process.cwd()`
Override the `base` of the vinyl file.
##### cwd
Type: `string`
Default: `process.cwd()`
Override the `cwd` (current working directory) of the vinyl file.
##### buffer
Type: `boolean`
Default: `true`
Setting this to `false` will return `file.contents` as a stream. This is useful when working with large files. **Note:** Plugins might not implement support for streams.
##### read
Type: `boolean`
Default: `true`
Setting this to `false` will return `file.contents` as null and not read the file at all.
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc