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

vinyl-fs

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinyl-fs - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

15

lib/dest/index.js

@@ -7,13 +7,22 @@ var map = require('map-stream');

var defaultMode = 0777 & (~process.umask());
module.exports = function(outFolder, opt) {
if (!opt) opt = {};
if (!opt.cwd) opt.cwd = process.cwd();
if (typeof opt.mode === 'string') opt.mode = parseInt(opt.mode, 8);
var cwd = path.resolve(opt.cwd);
var basePath = path.resolve(cwd, outFolder);
var folderMode = (opt.mode || defaultMode);
function saveFile (file, cb) {
var basePath = path.resolve(cwd, outFolder);
var writePath = path.resolve(basePath, file.relative);
var writeFolder = path.dirname(writePath);
if (typeof opt.mode !== 'undefined') {
if (!file.stat) file.stat = {};
file.stat.mode = opt.mode;
}
file.cwd = cwd;

@@ -25,3 +34,3 @@ file.base = basePath;

// then write to it
mkdirp(writeFolder, function(err){
mkdirp(writeFolder, folderMode, function(err){
if (err) return cb(err);

@@ -33,2 +42,2 @@ writeContents(writePath, file, cb);

return stream;
};
};
var fs = require('graceful-fs');
module.exports = function(writePath, file, cb) {
fs.writeFile(writePath, file.contents, cb);
};
var opt = {};
if (file.stat && typeof file.stat.mode !== 'undefined') {
opt.mode = file.stat.mode;
}
fs.writeFile(writePath, file.contents, opt, cb);
};

9

lib/dest/writeDir.js
var mkdirp = require('mkdirp');
module.exports = function (writePath, file, cb) {
// mode needs to be done
if (file.stat && typeof file.stat.mode !== 'undefined') {
mkdirp(writePath, file.stat.mode, cb);
return;
}
// no mode
mkdirp(writePath, cb);
};
};

@@ -0,10 +1,20 @@

var streamFile = require('../src/streamFile');
var fs = require('graceful-fs');
module.exports = function(writePath, file, cb) {
var outStream = fs.createWriteStream(writePath);
var opt = {};
if (file.stat && typeof file.stat.mode !== 'undefined') {
opt.mode = file.stat.mode;
}
var outStream = fs.createWriteStream(writePath, opt);
// TODO: can we pass the file along before the stream is unloaded?
file.contents.once('error', cb);
outStream.once('finish', cb);
file.contents.pipe(outStream).once('finish', function() {
streamFile(file, cb);
});
file.contents.pipe(outStream);
return outStream;
};
};
{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "0.0.2",
"version": "0.1.0",
"homepage": "http://github.com/wearefractal/vinyl-fs",

@@ -10,19 +10,19 @@ "repository": "git://github.com/wearefractal/vinyl-fs.git",

"dependencies": {
"vinyl": "~0.2.0",
"glob-stream": "~3.1.5",
"glob-watcher": "~0.0.1",
"mkdirp": "~0.3.5",
"graceful-fs": "~2.0.1",
"map-stream": "~0.1.0"
"vinyl": "^0.2.0",
"glob-stream": "^3.1.5",
"glob-watcher": "^0.0.3",
"mkdirp": "^0.3.5",
"graceful-fs": "^2.0.1",
"map-stream": "^0.1.0"
},
"devDependencies": {
"mocha": "~1.17.0",
"should": "~3.0.1",
"mocha-lcov-reporter": "0.0.1",
"coveralls": "~2.6.1",
"istanbul": "~0.2.3",
"rimraf": "~2.2.5",
"jshint": "~2.4.1",
"mocha": "^1.17.0",
"should": "^3.0.1",
"mocha-lcov-reporter": "^0.0.1",
"coveralls": "^2.6.1",
"istanbul": "^0.2.3",
"rimraf": "^2.2.5",
"jshint": "^2.4.1",
"buffer-equal": "0.0.0",
"through2": "~0.4.0"
"through2": "^0.4.0"
},

@@ -29,0 +29,0 @@ "scripts": {

@@ -6,3 +6,3 @@ # vinyl-fs [![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-fs)

<table>
<tr>
<tr>
<td>Package</td><td>vinyl-fs</td>

@@ -69,2 +69,3 @@ </tr>

- cwd - Specify the working directory the folder is relative to. Default is `process.cwd()`
- mode - Specify the mode the files should be created with. Default is the mode of the input file (file.stat.mode)
- Returns a Readable/Writable stream.

@@ -87,2 +88,2 @@ - On write the stream will save the [vinyl] File to disk at the folder/cwd specified.

[depstat-url]: https://david-dm.org/wearefractal/vinyl-fs
[depstat-image]: https://david-dm.org/wearefractal/vinyl-fs.png
[depstat-image]: https://david-dm.org/wearefractal/vinyl-fs.png

@@ -25,2 +25,6 @@ var vfs = require('../');

var realMode = function(n) {
return n & 07777;
};
describe('dest stream', function() {

@@ -155,2 +159,3 @@ beforeEach(wipeOut);

var expectedBase = path.join(__dirname, "./out-fixtures");
var expectedMode = 0655;

@@ -161,3 +166,6 @@ var expectedFile = new File({

path: inputPath,
contents: expectedContents
contents: expectedContents,
stat: {
mode: expectedMode
}
});

@@ -173,2 +181,3 @@

bufEqual(fs.readFileSync(expectedPath), expectedContents).should.equal(true);
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();

@@ -193,2 +202,3 @@ };

var expectedBase = path.join(__dirname, "./out-fixtures");
var expectedMode = 0655;

@@ -200,3 +210,6 @@ var contentStream = through.obj();

path: inputPath,
contents: contentStream
contents: contentStream,
stat: {
mode: expectedMode
}
});

@@ -212,2 +225,3 @@

bufEqual(fs.readFileSync(expectedPath), expectedContents).should.equal(true);
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();

@@ -235,2 +249,3 @@ };

var expectedBase = path.join(__dirname, "./out-fixtures");
var expectedMode = 0655;

@@ -245,3 +260,4 @@ var expectedFile = new File({

return true;
}
},
mode: expectedMode
}

@@ -258,2 +274,3 @@ });

fs.lstatSync(expectedPath).isDirectory().should.equal(true);
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();

@@ -271,2 +288,40 @@ };

it('should allow piping multiple dests in streaming mode', function(done) {
var inputPath1 = path.join(__dirname, "./out-fixtures/multiple-first");
var inputPath2 = path.join(__dirname, "./out-fixtures/multiple-second");
var inputBase = path.join(__dirname, "./out-fixtures/");
var srcPath = path.join(__dirname, "./fixtures/test.coffee");
var stream1 = vfs.dest('./out-fixtures/', {cwd: __dirname});
var stream2 = vfs.dest('./out-fixtures/', {cwd: __dirname});
var content = fs.readFileSync(srcPath);
var rename = through.obj(function(file, _, next) {
file.path = inputPath2;
this.push(file);
next();
});
stream1.on('data', function(file) {
file.path.should.equal(inputPath1);
})
stream1.pipe(rename).pipe(stream2);
stream2.on('data', function(file) {
file.path.should.equal(inputPath2);
}).once('end', function() {
fs.readFileSync(inputPath1, 'utf8').should.equal(content.toString());
fs.readFileSync(inputPath2, 'utf8').should.equal(content.toString());
done();
});
var file = new File({
base: inputBase,
path: inputPath1,
cwd: __dirname,
contents: content
})
stream1.write(file);
stream1.end();
})
});
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