Socket
Socket
Sign inDemoInstall

vinyl

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinyl - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

23

index.js

@@ -14,7 +14,10 @@ var path = require('path');

// TODO: should this be moved to vinyl-fs?
this.cwd = file.cwd || process.cwd();
this.base = file.base || this.cwd;
this.path = file.path || null;
// stat = fs stats object
// TODO: should this be moved to vinyl-fs?
this.stat = file.stat || null;

@@ -38,2 +41,3 @@

// TODO: should this be moved to vinyl-fs?
File.prototype.isDirectory = function() {

@@ -56,12 +60,22 @@ return this.isNull() && this.stat && this.stat.isDirectory();

File.prototype.pipe = function(stream) {
File.prototype.pipe = function(stream, opt) {
if (!opt) opt = {};
if (typeof opt.end === 'undefined') opt.end = true;
if (this.isStream()) {
return this.contents.pipe(stream);
return this.contents.pipe(stream, opt);
}
if (this.isBuffer()) {
stream.write(this.contents);
if (opt.end) {
stream.end(this.contents);
} else {
stream.write(this.contents);
}
return stream;
}
if (this.isNull()) {
if (opt.end) stream.end();
return stream;
}
// must be null, dont do anything
return stream;

@@ -105,2 +119,3 @@ };

// TODO: should this be moved to vinyl-fs?
Object.defineProperty(File.prototype, 'relative', {

@@ -107,0 +122,0 @@ get: function() {

2

package.json
{
"name": "vinyl",
"description": "A virtual file format",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "http://github.com/wearefractal/vinyl",

@@ -6,0 +6,0 @@ "repository": "git://github.com/wearefractal/vinyl.git",

@@ -85,3 +85,3 @@ [![Build Status](https://travis-ci.org/wearefractal/vinyl.png?branch=master)](https://travis-ci.org/wearefractal/vinyl)

### pipe(stream)
### pipe(stream[, opt])

@@ -94,2 +94,4 @@ If file.contents is a Buffer, it will write it to the stream.

If opt.end is true, the destination stream will not be ended (same as node core).
Returns the stream.

@@ -96,0 +98,0 @@

@@ -248,2 +248,4 @@ var File = require('../');

chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
});
stream.on('end', function(chunk) {
done();

@@ -289,4 +291,73 @@ });

});
stream.on('end', function() {
done();
});
var ret = file.pipe(stream);
ret.should.equal(stream, 'should return the stream');
});
it('should write to stream with Buffer', function(done) {
var options = {
cwd: "/",
base: "/test/",
path: "/test/test.coffee",
contents: new Buffer("test")
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
done();
});
stream.on('end', function(chunk) {
throw new Error("should not end");
});
var ret = file.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
});
it('should pipe to stream with Stream', function(done) {
var testChunk = new Buffer("test");
var options = {
cwd: "/",
base: "/test/",
path: "/test/test.coffee",
contents: new Stream.PassThrough()
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(testChunk.toString('utf8'));
done();
});
stream.on('end', function(chunk) {
throw new Error("should not end");
});
var ret = file.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
file.contents.write(testChunk);
});
it('should do nothing with null', function(done) {
var options = {
cwd: "/",
base: "/test/",
path: "/test/test.coffee",
contents: null
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
throw new Error("should not write");
});
stream.on('end', function(chunk) {
throw new Error("should not end");
});
var ret = file.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
process.nextTick(done);

@@ -293,0 +364,0 @@ });

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